This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CommonCrypto/CommonDigest.h> | |
#include <CommonCrypto/CommonHMAC.h> | |
@interface ZRCommonCryption : NSObject | |
/** | |
* 加密方式,MAC算法: HmacSHA256 | |
* | |
* @param plaintext 要加密的文本 | |
* @param key 秘钥 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief URLEncode 对字符串URL编码 | |
* | |
* @param str 原字符串 | |
* @param strSize 原字符串长度(不包括最后的\0) | |
* @param result 结果缓冲区的地址 | |
* @param resultSize 结果缓冲区的大小(包括最后的\0) | |
* | |
* @return: >0:resultstring 里实际有效的长度 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <zlib.h> | |
/* | |
* A good example for using zlib is correlated de/compress file instead of string | |
*/ | |
void decompress_one_file(char *infilename, char *outfilename); | |
void compress_one_file(char *infilename, char *outfilename); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CompressByGZIP(std::string & uncompressedStr, std::string & compressedStr) | |
{ | |
if (uncompressedStr.length() <= 0) { | |
return false; | |
} | |
compressedStr.resize(uncompressedStr.size() * 1.5 + 12); | |
/* Before we can begin compressing (aka "deflating") data using the zlib | |
functions, we must initialize zlib. Normally this is done by calling the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface MyView : UIView | |
@property (nonatomic, assign) BOOL isMySelf; | |
@end | |
@implementation MyView | |
- (instancetype)init | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <codecvt> | |
std::string VLUtilitiesEncoding::UTF8Encoding(std::string & unencodedStr) | |
{ | |
if (unencodedStr.length() <= 0) return ""; | |
std::wstring_convert<std::codecvt_utf8<wchar_t>,wchar_t> conversion; | |
std::wstring wbodyStr = conversion.from_bytes(unencodedStr); | |
return conversion.to_bytes(wbodyStr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zlib.h> | |
#include <sstream> | |
/** Compress a STL string using zlib with given compression level and return | |
* the binary data. | |
https://panthema.net/2007/0328-ZLibString.html | |
*/ | |
std::string VLUtilitiesEncoding::compress(const std::string & str, int compressionlevel = Z_BEST_COMPRESSION) | |
{ | |
z_stream zs; // z_stream is zlib's control structure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Create public key/private key file, actually, the original certificates was modified to a XML file | |
/// 创建公钥/私钥文件,其实就是把原有的证书的内容修改成XML格式的 | |
/// </summary> | |
public static void CreateCertificateKeyXML(string path, string key) | |
{ | |
try | |
{ | |
FileStream keyxml = new FileStream(path, FileMode.Create); | |
StreamWriter sw = new StreamWriter(keyxml); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This file is encrypt/decrypt data in a default way which can not decrypt/decrypt a chunk of data | |
using System; | |
using System.Text; | |
using System.Security.Cryptography; | |
using System.Security.Cryptography.X509Certificates; | |
namespace RSA_CSharp_Example | |
{ | |
class Program |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface RSACryptographic : NSObject | |
- (void)loadPublicKeyFromFile:(NSString*)derFilePath; | |
- (void)loadPublicKeyFromData:(NSData*)derData; | |
- (void)loadPrivateKeyFromFile:(NSString*)p12FilePath password:(NSString*)p12Password; | |
- (void)loadPrivateKeyFromData:(NSData*)p12Data password:(NSString*)p12Password; |
OlderNewer