iOS安全加密:AES-RSA-For-iOS
iOS,安全加密。采用RSA簽名和AES隨機秘鑰加密,AES的隨機秘鑰采用RSA加密。密碼0123456789abcdef?加密字段1加密結果:2yPBJGtAg/AfuvT8idAmzw==
NSMutableDictionary *resultDic = [[NSMutableDictionary alloc]initWithCapacity:1];
//step1 對報文數據源排序a->z
NSMutableArray *sortedArray = [self sortDictionary:EncryptDic];
//step2 取出排序過后數組的value,拼成string
NSMutableArray *arrayOfValues = [NSMutableArray arrayWithArray:sortedArray];
NSString *paramValue = [arrayOfValues componentsJoinedByString:@""];
//step3 根據RAS私有密鑰簽名業務請求參數值字符串(paramValue),生成基于SHA1的RSA數字簽名
CRSA *t = [CRSA shareInstance];
NSString *sign = [t encryptByRsa:paramValue withKeyType:KeyTypePrivate];
//step4 將簽名放入原報文
NSMutableDictionary *dicWithSign = [NSMutableDictionary dictionaryWithDictionary:EncryptDic];
[dicWithSign setObject:sign forKey:@"sign"];
//step5 隨機生成16位數字和字母組成的
NSString *merchantAesKey = [LcAESRSA set32bitString:16];
NSLog(@"\rAES key :%@",merchantAesKey);
//step6 用16位隨機碼加密含有簽名的報文
SBJsonWriter * parser = [[SBJsonWriter alloc]init];
NSString * realdata = [parser stringWithObject:dicWithSign];
NSString *Stringdata = [NSData AES256EncryptWithPlainText:realdata key:merchantAesKey];
//step7 使用 RSA 加密 merchantAesKey 生成密鑰密文:
NSString *Stringencryptkey = [t encryptByRsa:merchantAesKey withKeyType:KeyTypePublic];
[resultDic setObject:Stringdata forKey:@"data"];
[resultDic setObject:Stringencryptkey forKey:@"encryptKey"]; 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!