RSA算法是一种非对称加密算法

作者: 时时彩平台-编程  发布:2019-09-13

RSA算法是一种非对称加密算法,常被用于加密数据传输.如果配合上数字摘要算法, 也可以用于文件签名.

RSA算法作用:一个是加密一个是加签。**1.加密: **是使用公钥能在客户端加密数据,在服务器端用私钥解密。仅仅为了加密**2.加签: **是用私钥在客户端加签,然后用公钥在服务器端用公钥验签。加签是为了放抵赖,就是为了防止别人模拟我们的客户端来攻击我们的服务器,从而导致瘫痪。

RSA基本原理:RSA使用"秘匙对"对数据进行加密解密.在加密解密数据前,需要先生成公钥(public key)和私钥(private key)。**公钥(public key): **用于加密数据. 用于公开, 一般存放在数据提供方, 例如iOS客户端。私钥(private key): 用于解密数据. 必须保密, 私钥泄露会造成安全问题。

RSA的公钥、私钥的组成,以及加密、解密的公式可见于下图:

图片 1

在加密和解密中,我们需要了解的知识有什么是openssl;RSA加密算法的基本原理;如何通过openssl生成最后我们需要的der和p12文件。

iOS客户端的加解密首先我们需要导入Security.framework

在iOS中,我们主要关注四个函数SecKeyEncrypt:使用公钥对数据进行加密SecKeyDecrypt:使用私钥对数据进行解密SecKeyRawVerify:使用公钥对数字签名和数据进行验证,以确认该数据的来源合法性。什么是数字签名,可以参考百度百科这篇文章?SecKeyRawSign:使用私钥对数据进行摘要并生成数字签名

详情见步骤:

  1. 使用openssl生成密匙对, 最后需要得到公钥证书和私钥证书
  2. 验证证书
  3. 新建用于加密、解密的类RSAEncryptor, 并实现相关方法
  4. 在项目中测试加密、解密

MAC OS自带了OpenSSL,所以直接在命令行里使用OPENSSL就可以。进入其中的你需要的目录(方便你等会下载:rsa_private_key.pem、rsa_public_key.pem,执行以下命令:

// 生成长度为 1024 的私钥:rsa_private_key.pemopenssl genrsa -out rsa_private_key.pem 1024// 使用私钥文件创建所需的证书:openssl req -new -key rsa_private_key.pem -out rsaCertReq.csr// 使用 x509 创建证书:rsaCert.crtopenssl x509 -req -days 3650 -in rsaCertReq.csr -signkey rsa_private_key.pem -out rsaCert.crt// Create rsa_public_key.der For IOS. 生成 .der 格式的公钥:rsa_public_key.deropenssl x509 -outform der -in rsaCert.crt -out rsa_public_key.der// Create rsa_private_key.p12 For IOS. 这一步生成解密所需 .p12文件,请记住你输入的密码,IOS代码里会用到openssl pkcs12 -export -out rsa_private_key.p12 -inkey rsa_private_key.pem -in rsaCert.crt// Create rsa_public_key.pem For Javaopenssl rsa -in rsa_private_key.pem -out rsa_public_key.pem -pubout// 把RSA私钥转换成PKCS8格式, 密码为空也行,openssl pkcs8 -topk8 -in rsa_private_key.pem -out pkcs8_private_key.pem -nocrypt

在命令行种可能需要你的一些信息去生成公钥和私钥

Country Name (2 letter code) [AU]:CN // 国家码State or Province Name (full name) [Some-State]:china //地区码Locality Name  []:beijing // 本地码Organization Name (eg, company) [Internet Widgits Pty Ltd]: // 公司名称Organizational Unit Name (eg, section) []:Development Department // 部门Common Name (eg, YOUR name) []: // 名字Email Address []: //邮箱

注意:在生成密钥对的时候需要填入 私钥的提取密码,请记住,解密的时候需要用到。

从上面看出通过私钥能生成对应的公钥,因此我们将私钥private_key.pem用在服务器端,公钥发放给android跟ios等前端

图片 2

iOS用到的是rsa_public_key.der和rsa_private_key.p12

图片 3

把rsa_public_key.der拖到xcode中,如果文件没有问题的话,那么就可以直接在xcode中打开,看到证书的各种信息。导入到项目中不要直接拖拽进去,而是右键选择add files to ""新建项目后添加库:Security.framework

图片 4

可以直接复制粘贴下来使用RSAEncryptor.h 文件:

#import <Foundation/Foundation.h>@interface RSAEncryptor : NSObject/** * 加密方法 * * @param str 需要加密的字符串 * @param path '.der'格式的公钥文件路径 */+ (NSString *)encryptString:(NSString *)str publicKeyWithContentsOfFile:(NSString *)path;/** * 解密方法 * * @param str 需要解密的字符串 * @param path '.p12'格式的私钥文件路径 * @param password 私钥文件密码 */+ (NSString *)decryptString:(NSString *)str privateKeyWithContentsOfFile:(NSString *)path password:(NSString *)password;/** * 加密方法 * * @param str 需要加密的字符串 * @param pubKey 公钥字符串 */+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;/** * 解密方法 * * @param str 需要解密的字符串 * @param privKey 私钥字符串 */+ (NSString *)decryptString:(NSString *)str privateKey:(NSString *)privKey;@end

RSAEncryptor.m 文件:

#import "RSAEncryptor.h"#import <Security/Security.h>@implementation RSAEncryptorstatic NSString *base64_encode_data(NSData *data){ data = [data base64EncodedDataWithOptions:0]; NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; return ret;}static NSData *base64_decode(NSString *str){ NSData *data = [[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters]; return data;}#pragma mark - 使用'.der'公钥文件加密//加密+ (NSString *)encryptString:(NSString *)str publicKeyWithContentsOfFile:(NSString *)path{ if (!str || !path) return nil; return [self encryptString:str publicKeyRef:[self getPublicKeyRefWithContentsOfFile:path]];}//获取公钥+ (SecKeyRef)getPublicKeyRefWithContentsOfFile:(NSString *)filePath{ NSData *certData = [NSData dataWithContentsOfFile:filePath]; if (!certData) { return nil; } SecCertificateRef cert = SecCertificateCreateWithData(NULL, (CFDataRef)certData); SecKeyRef key = NULL; SecTrustRef trust = NULL; SecPolicyRef policy = NULL; if (cert != NULL) { policy = SecPolicyCreateBasicX509(); if  { if (SecTrustCreateWithCertificates((CFTypeRef)cert, policy, &trust) == noErr) { SecTrustResultType result; if (SecTrustEvaluate(trust, &result) == noErr) { key = SecTrustCopyPublicKey; } } } } if  CFRelease; if  CFRelease; if  CFRelease; return key;}+ (NSString *)encryptString:(NSString *)str publicKeyRef:(SecKeyRef)publicKeyRef{ if(![str dataUsingEncoding:NSUTF8StringEncoding]){ return nil; } if(!publicKeyRef){ return nil; } NSData *data = [self encryptData:[str dataUsingEncoding:NSUTF8StringEncoding] withKeyRef:publicKeyRef]; NSString *ret = base64_encode_data; return ret;}#pragma mark - 使用'.12'私钥文件解密//解密+ (NSString *)decryptString:(NSString *)str privateKeyWithContentsOfFile:(NSString *)path password:(NSString *)password{ if (!str || !path) return nil; if (!password) password = @""; return [self decryptString:str privateKeyRef:[self getPrivateKeyRefWithContentsOfFile:path password:password]];}//获取私钥+ (SecKeyRef)getPrivateKeyRefWithContentsOfFile:(NSString *)filePath password:(NSString*)password{ NSData *p12Data = [NSData dataWithContentsOfFile:filePath]; if  { return nil; } SecKeyRef privateKeyRef = NULL; NSMutableDictionary * options = [[NSMutableDictionary alloc] init]; [options setObject: password forKey:(__bridge id)kSecImportExportPassphrase]; CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL); OSStatus securityError = SecPKCS12Import((__bridge CFDataRef) p12Data, (__bridge CFDictionaryRef)options, &items); if (securityError == noErr && CFArrayGetCount > 0) { CFDictionaryRef identityDict = CFArrayGetValueAtIndex; SecIdentityRef identityApp = (SecIdentityRef)CFDictionaryGetValue(identityDict, kSecImportItemIdentity); securityError = SecIdentityCopyPrivateKey(identityApp, &privateKeyRef); if (securityError != noErr) { privateKeyRef = NULL; } } CFRelease; return privateKeyRef;}+ (NSString *)decryptString:(NSString *)str privateKeyRef:(SecKeyRef)privKeyRef{ NSData *data = [[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters]; if (!privKeyRef) { return nil; } data = [self decryptData:data withKeyRef:privKeyRef]; NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; return ret;}#pragma mark - 使用公钥字符串加密/* START: Encryption with RSA public key *///使用公钥字符串加密+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey{ NSData *data = [self encryptData:[str dataUsingEncoding:NSUTF8StringEncoding] publicKey:pubKey]; NSString *ret = base64_encode_data; return ret;}+ encryptData:data publicKey:(NSString *)pubKey{ if(!data || !pubKey){ return nil; } SecKeyRef keyRef = [self addPublicKey:pubKey]; if{ return nil; } return [self encryptData:data withKeyRef:keyRef];}+ (SecKeyRef)addPublicKey:(NSString *)key{ NSRange spos = [key rangeOfString:@"-----BEGIN PUBLIC KEY-----"]; NSRange epos = [key rangeOfString:@"-----END PUBLIC KEY-----"]; if(spos.location != NSNotFound && epos.location != NSNotFound){ NSUInteger s = spos.location + spos.length; NSUInteger e = epos.location; NSRange range = NSMakeRange; key = [key substringWithRange:range]; } key = [key stringByReplacingOccurrencesOfString:@"r" withString:@""]; key = [key stringByReplacingOccurrencesOfString:@"n" withString:@""]; key = [key stringByReplacingOccurrencesOfString:@"t" withString:@""]; key = [key stringByReplacingOccurrencesOfString:@" " withString:@""]; // This will be base64 encoded, decode it. NSData *data = base64_decode; data = [self stripPublicKeyHeader:data]; if{ return nil; } //a tag to read/write keychain storage NSString *tag = @"RSAUtil_PubKey"; NSData *d_tag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]]; // Delete any old lingering key with the same tag NSMutableDictionary *publicKey = [[NSMutableDictionary alloc] init]; [publicKey setObject:(__bridge id) kSecClassKey forKey:(__bridge id)kSecClass]; [publicKey setObject:(__bridge id) kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; [publicKey setObject:d_tag forKey:(__bridge id)kSecAttrApplicationTag]; SecItemDelete((__bridge CFDictionaryRef)publicKey); // Add persistent version of the key to system keychain [publicKey setObject:data forKey:(__bridge id)kSecValueData]; [publicKey setObject:(__bridge id) kSecAttrKeyClassPublic forKey:(__bridge id) kSecAttrKeyClass]; [publicKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id) kSecReturnPersistentRef]; CFTypeRef persistKey = nil; OSStatus status = SecItemAdd((__bridge CFDictionaryRef)publicKey, &persistKey); if (persistKey != nil){ CFRelease(persistKey); } if ((status != noErr) && (status != errSecDuplicateItem)) { return nil; } [publicKey removeObjectForKey:(__bridge id)kSecValueData]; [publicKey removeObjectForKey:(__bridge id)kSecReturnPersistentRef]; [publicKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnRef]; [publicKey setObject:(__bridge id) kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; // Now fetch the SecKeyRef version of the key SecKeyRef keyRef = nil; status = SecItemCopyMatching((__bridge CFDictionaryRef)publicKey, (CFTypeRef *)&keyRef); if(status != noErr){ return nil; } return keyRef;}+ stripPublicKeyHeader:d_key{ // Skip ASN.1 public key header if (d_key == nil) return; unsigned long len = [d_key length]; if  return; unsigned char *c_key = (unsigned char *)[d_key bytes]; unsigned int idx = 0; if (c_key[idx++] != 0x30) return; if (c_key[idx] > 0x80) idx += c_key[idx] - 0x80 + 1; else idx++; // PKCS #1 rsaEncryption szOID_RSA_RSA static unsigned char seqiod[] = { 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00 }; if (memcmp(&c_key[idx], seqiod, 15)) return; idx += 15; if (c_key[idx++] != 0x03) return; if (c_key[idx] > 0x80) idx += c_key[idx] - 0x80 + 1; else idx++; if (c_key[idx++] != '') return; // Now make a new NSData from this buffer return ([NSData dataWithBytes:&c_key[idx] length:len - idx]);}+ encryptData:data withKeyRef:(SecKeyRef) keyRef{ const uint8_t *srcbuf = (const uint8_t *)[data bytes]; size_t srclen = data.length; size_t block_size = SecKeyGetBlockSize * sizeof; void *outbuf = malloc(block_size); size_t src_block_size = block_size - 11; NSMutableData *ret = [[NSMutableData alloc] init]; for(int idx=0; idx<srclen; idx+=src_block_size){ //NSLog(@"%d/%d block_size: %d", idx, srclen, block_size); size_t data_len = srclen - idx; if(data_len > src_block_size){ data_len = src_block_size; } size_t outlen = block_size; OSStatus status = noErr; status = SecKeyEncrypt(keyRef, kSecPaddingPKCS1, srcbuf + idx, data_len, outbuf, &outlen ); if (status != 0) { NSLog(@"SecKeyEncrypt fail. Error Code: %d", status); ret = nil; break; }else{ [ret appendBytes:outbuf length:outlen]; } } free; CFRelease; return ret;}/* END: Encryption with RSA public key */#pragma mark - 使用私钥字符串解密/* START: Decryption with RSA private key *///使用私钥字符串解密+ (NSString *)decryptString:(NSString *)str privateKey:(NSString *)privKey{ if  return nil; NSData *data = [[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters]; data = [self decryptData:data privateKey:privKey]; NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; return ret;}+ decryptData:data privateKey:(NSString *)privKey{ if(!data || !privKey){ return nil; } SecKeyRef keyRef = [self addPrivateKey:privKey]; if{ return nil; } return [self decryptData:data withKeyRef:keyRef];}+ (SecKeyRef)addPrivateKey:(NSString *)key{ NSRange spos = [key rangeOfString:@"-----BEGIN RSA PRIVATE KEY-----"]; NSRange epos = [key rangeOfString:@"-----END RSA PRIVATE KEY-----"]; if(spos.location != NSNotFound && epos.location != NSNotFound){ NSUInteger s = spos.location + spos.length; NSUInteger e = epos.location; NSRange range = NSMakeRange; key = [key substringWithRange:range]; } key = [key stringByReplacingOccurrencesOfString:@"r" withString:@""]; key = [key stringByReplacingOccurrencesOfString:@"n" withString:@""]; key = [key stringByReplacingOccurrencesOfString:@"t" withString:@""]; key = [key stringByReplacingOccurrencesOfString:@" " withString:@""]; // This will be base64 encoded, decode it. NSData *data = base64_decode; data = [self stripPrivateKeyHeader:data]; if{ return nil; } //a tag to read/write keychain storage NSString *tag = @"RSAUtil_PrivKey"; NSData *d_tag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]]; // Delete any old lingering key with the same tag NSMutableDictionary *privateKey = [[NSMutableDictionary alloc] init]; [privateKey setObject:(__bridge id) kSecClassKey forKey:(__bridge id)kSecClass]; [privateKey setObject:(__bridge id) kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; [privateKey setObject:d_tag forKey:(__bridge id)kSecAttrApplicationTag]; SecItemDelete((__bridge CFDictionaryRef)privateKey); // Add persistent version of the key to system keychain [privateKey setObject:data forKey:(__bridge id)kSecValueData]; [privateKey setObject:(__bridge id) kSecAttrKeyClassPrivate forKey:(__bridge id) kSecAttrKeyClass]; [privateKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id) kSecReturnPersistentRef]; CFTypeRef persistKey = nil; OSStatus status = SecItemAdd((__bridge CFDictionaryRef)privateKey, &persistKey); if (persistKey != nil){ CFRelease(persistKey); } if ((status != noErr) && (status != errSecDuplicateItem)) { return nil; } [privateKey removeObjectForKey:(__bridge id)kSecValueData]; [privateKey removeObjectForKey:(__bridge id)kSecReturnPersistentRef]; [privateKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnRef]; [privateKey setObject:(__bridge id) kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; // Now fetch the SecKeyRef version of the key SecKeyRef keyRef = nil; status = SecItemCopyMatching((__bridge CFDictionaryRef)privateKey, (CFTypeRef *)&keyRef); if(status != noErr){ return nil; } return keyRef;}+ stripPrivateKeyHeader:d_key{ // Skip ASN.1 private key header if (d_key == nil) return; unsigned long len = [d_key length]; if  return; unsigned char *c_key = (unsigned char *)[d_key bytes]; unsigned int idx = 22; //magic byte at offset 22 if (0x04 != c_key[idx++]) return nil; //calculate length of the key unsigned int c_len = c_key[idx++]; int det = c_len & 0x80; if  { c_len = c_len & 0x7f; } else { int byteCount = c_len & 0x7f; if (byteCount + idx > len) { //rsa length field longer than buffer return nil; } unsigned int accum = 0; unsigned char *ptr = &c_key[idx]; idx += byteCount; while (byteCount) { accum = (accum << 8) + *ptr; ptr++; byteCount--; } c_len = accum; } // Now make a new NSData from this buffer return [d_key subdataWithRange:NSMakeRange(idx, c_len)];}+ decryptData:data withKeyRef:(SecKeyRef) keyRef{ const uint8_t *srcbuf = (const uint8_t *)[data bytes]; size_t srclen = data.length; size_t block_size = SecKeyGetBlockSize * sizeof; UInt8 *outbuf = malloc(block_size); size_t src_block_size = block_size; NSMutableData *ret = [[NSMutableData alloc] init]; for(int idx=0; idx<srclen; idx+=src_block_size){ //NSLog(@"%d/%d block_size: %d", idx, srclen, block_size); size_t data_len = srclen - idx; if(data_len > src_block_size){ data_len = src_block_size; } size_t outlen = block_size; OSStatus status = noErr; status = SecKeyDecrypt(keyRef, kSecPaddingNone, srcbuf + idx, data_len, outbuf, &outlen ); if (status != 0) { NSLog(@"SecKeyEncrypt fail. Error Code: %d", status); ret = nil; break; }else{ //the actual decrypted data is in the middle, locate it! int idxFirstZero = -1; int idxNextZero = outlen; for ( int i = 0; i < outlen; i++ ) { if ( outbuf[i] == 0 ) { if ( idxFirstZero < 0 ) { idxFirstZero = i; } else { idxNextZero = i; break; } } } [ret appendBytes:&outbuf[idxFirstZero+1] length:idxNextZero-idxFirstZero-1]; } } free; CFRelease; return ret;}/* END: Decryption with RSA private key */@end

1.测试使用.der和.p12秘钥文件进行加密、解密

 //原始数据 NSString *originalString = @"这是一段将要使用'.der'文件加密的字符串!"; //使用.der和.p12中的公钥私钥加密解密 NSString *public_key_path = [[NSBundle mainBundle] pathForResource:@"rsa_public_key.der" ofType:nil]; NSString *private_key_path = [[NSBundle mainBundle] pathForResource:@"rsa_private_key.p12" ofType:nil]; NSString *encryptStr = [RSAEncryptor encryptString:originalString publicKeyWithContentsOfFile:public_key_path]; NSLog(@"加密前:%@", originalString); NSLog(@"加密后:%@", encryptStr); NSLog(@"解密后:%@", [RSAEncryptor decryptString:encryptStr privateKeyWithContentsOfFile:private_key_path password:@"123456"]);

2.测试使用秘钥字符串进行加密、解密, 在线生成RSA秘钥:, 生成公钥和秘钥后, 复制出来用于测试.

//原始数据 NSString *originalString = @"这是一段将要使用'秘钥字符串'进行加密的字符串!"; //使用字符串格式的公钥私钥加密解密 NSString *encryptStr = [RSAEncryptor encryptString:originalString publicKey:@"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTbZ6cNH9PgdF60aQKveLz3FTalyzHQwbp601y77SzmGHX3F5NoVUZbdK7UMdoCLK4FBziTewYD9DWvAErXZo9BFuI96bAop8wfl1VkZyyHTcznxNJFGSQd/B70/ExMgMBpEwkAAdyUqIjIdVGh1FQK/4acwS39YXwbS+IlHsPSQIDAQAB"]; NSLog(@"加密前:%@", originalString); NSLog(@"加密后:%@", encryptStr); NSLog(@"解密后:%@", [RSAEncryptor decryptString:encryptStr privateKey:@"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANNtnpw0f0+B0XrRpAq94vPcVNqXLMdDBunrTXLvtLOYYdfcXk2hVRlt0rtQx2gIsrgUHOJN7BgP0Na8AStdmj0EW4j3psCinzB+XVWRnLIdNzOfE0kUZJB38HvT8TEyAwGkTCQAB3JSoiMh1UaHUVAr/hpzBLf1hfBtL4iUew9JAgMBAAECgYA1tGeQmAkqofga8XtwuxEWDoaDS9k0+EKeUoXGxzqoT/GyiihuIafjILFhoUA1ndf/yCQaG973sbTDhtfpMwqFNQq13+JAownslTjWgr7Hwf7qplYW92R7CU0v7wFfjqm1t/2FKU9JkHfaHfb7qqESMIbO/VMjER9o4tEx58uXDQJBAO0O4lnWDVjr1gN02cqvxPOtTY6DgFbQDeaAZF8obb6XqvCqGW/AVms3Bh8nVlUwdQ2K/xte8tHxjW9FtBQTLd8CQQDkUncO35gAqUF9Bhsdzrs7nO1J3VjLrM0ITrepqjqtVEvdXZc+1/UrkWVaIigWAXjQCVfmQzScdbznhYXPz5fXAkEAgB3KMRkhL4yNpmKRjhw+ih+ASeRCCSj6Sjfbhx4XaakYZmbXxnChg+JB+bZNz06YBFC5nLZM7y/n61o1f5/56wJBALw+ZVzE6ly5L34114uG04W9x0HcFgau7MiJphFjgUdAtd/H9xfgE4odMRPUD3q9Me9LlMYK6MiKpfm4c2+3dzcCQQC8y37NPgpNEkd9smMwPpSEjPW41aMlfcKvP4Da3z7G5bGlmuICrva9YDAiaAyDGGCK8LxC8K6HpKrFgYrXkRtt"]);

项目中必定多处使用, 可以封装一下请求, 在上传接口里参数加密,后台解密即可.我这里使用 afn ,再次自定义一次请求,仅供参考.

+ post:(NSString *)url params:params success:success failure:(NSError *error))failure { // 1.请求管理者 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; // 2.拼接请求参数url 在具体控制器请求里传入 // 拼接参数加密 NSString *public_key_path = [[NSBundle mainBundle] pathForResource:@"rsa_public_key.der" ofType:nil]; NSString *encryptStr = [RSAEncryptor encryptString:params publicKeyWithContentsOfFile:public_key_path]; // 3.发送请求 [manager POST:url parameters:encryptStr success:^(NSURLSessionDataTask *task, id responseObject) { if  { success(responseObject); } } failure:^(NSURLSessionDataTask *task, NSError *error) { if  { failure; } }]; }

可以测试

本文由时时彩平台发布于时时彩平台-编程,转载请注明出处:RSA算法是一种非对称加密算法

关键词: