提问人:user_Dennis_Mostajo 提问时间:5/15/2021 最后编辑:user_Dennis_Mostajo 更新时间:5/16/2021 访问量:196
为什么我的 AES 256 解密方法在 iOS 14 上不起作用
Why my AES 256 decrypt method not working iOS 14
问:
在获取后端响应后,我正在尝试使用 AES 256 方法从 JSON 解密字符串值,每个值都正确解析,但是当我尝试解密加密的字符串值时,我的方法总是返回 null,JSON 响应是:
dataResponseString: {
"subjects": [
{
"name": "test1",
"version": 1,
"createdAt": "2021-05-12T03:15:12.741Z",
"createdBy": "dmostajo",
"subject": "WLSdQGDlb2CbBtKoK/ukbYv1HOl5ZVZo9P5VRV9426GMurhKD5o7U53MfvYaLmogJCYz32s8uz4B0HxBawlph3sgfdDieA3Lxh8D4WLLXqwY2psVasukKV1HTR9Jst1cI3O/vorvheSRvBb4JZQYotmhVPsjEkSc2xJ5ewyBCL0uv3VRWwe4qhB94Q1F/EowW5s3aH9CRlf/H9hJg1ougyX1ZL02OydMrFMXCwZSALHKLT6kCase/oHTTGyuDvs8xzLk3QSBiUO2G9ppeXmRxYB/sPAFpDI8eV2T5/O+xlIP/LLE/eyKe+wEfxWlKG1uAwiVhfrHmFMueRG7Hv6DJ/s63M2o3vziB6zfX832rQc="
},
{
"name": "test2",
"version": 1,
"createdAt": "2021-04-15T16:16:35.206Z",
"createdBy": "dmostajo",
"subject": "WLSdQGDlb2CbBtKoK/ukbc1429tOxdpzEE6W/leNEoWJCIzf+R7D6u+FSu1JDXgIGiF5pgh5BJQK3yNJVYxLYsaL3kpP2yL2ALPILY6WdWBA/GJFo3s6Y0rMeEh4UBkb/yDNqbZhK2hrn3e+zvFQYG6i0+rE3rhXkTlRcRWmXB0JRTg7pTt2BtNOe+CynG3SgwowYv+R/244Ab6z/Tg+ejKs41wrKCJcBsiU5Yl18oUCeiycmQYtgRoX+yz2o5X1F/arIDi2pdCBIIS1n7sII+woRL2C0o9N5YJl3zzWnF0RwxmkSPKz7j71+sHO4OIGw+tiaKPDTfQf3K0ViQezEVHO9jAxPglkcEtMm5T1A/dWSTZQv4HjAwQ8ZjmZ5Y25Qki7oQgNStyKPxHafINj8g=="
}
]
}
我使用的整个代码是:
- 要从后端获取响应,请执行以下操作:
-(void)getSubjects
{
NSLog(@"Decoding AccessToken:%@",[JWTDecoder decodeJWTToken:[[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]]);
NSString *strAuthHeader = [NSString stringWithFormat:@"Bearer %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]];
NSDictionary *authHeaders = @{ @"authorization": strAuthHeader };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://myclientservertest/api/v2/subjects"] cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:authHeaders];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *responseAuth, NSError *error)
{
if (error)
{
dispatch_async(dispatch_get_main_queue(),
^{
[NLCCommonViewController showAlert:ERR_NETWORK];
});
}
else
{
NSString *dataResponseString= [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"responseAuth:%@",responseAuth);
NSLog(@"dataResponseString:%@",dataResponseString);
if([(NSHTTPURLResponse *)responseAuth statusCode] == 200)
{
NSError *errorJson;
// NSData *data = [dataResponseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&errorJson];
NSMutableArray *subjects = [json objectForKey:@"subjects"];
for (NSMutableDictionary * dict in subjects)
{
NSString *appName = [dict valueForKey:@"name"];
NSString *version = [dict valueForKey:@"version"];
NSString *createdAt = [dict valueForKey:@"createdAt"];
NSString *createdBy = [dict valueForKey:@"createdBy"];
NSString *subject = [dict valueForKey:@"subject"];
NSLog(@"subject:%@",subject);
NSString *secret =[self md5:[NSString stringWithFormat:@"%@:CLIENT_VALUE",createdBy]];
NSData *subjectData = [[NSData alloc] initWithBase64EncodedString:subject options:0];
NSString *decrypted = [CustomAESHelper decryptData:subjectData withKey:secret];
NSLog(@"decrypted:%@",decrypted);
}
}
else
{
}
}
}];
[dataTask resume];
}
- md5 方法工作正常:
- (NSString*)md5:(NSString*)str {
NSString *salt = @"";
NSString *strWithSalt = [NSString stringWithFormat:@"%@%@",str,salt];
const char *cStr = [strWithSalt UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, (CC_LONG) strlen(cStr), result );
return [[NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1],
result[2], result[3],
result[4], result[5],
result[6], result[7],
result[8], result[9],
result[10], result[11],
result[12], result[13],
result[14], result[15]
] lowercaseString];
}
- AES 帮助程序:
#import <UIKit/UIKit.h>
#import <CommonCrypto/CommonCryptor.h>
@interface CustomAESHelper : UIViewController
+ (NSString*) encryptString:(NSString*)plaintext withKey:(NSString*)key;
+ (NSString*) encryptNSMutableArray:(NSMutableArray *)mutableArray withKey:(NSString *)key;
+ (NSString*) decryptData:(NSData*)ciphertext withKey:(NSString*)key;
@end
#import "CustomAESHelper.h"
@implementation NSData (AESAdditions)
- (NSData *)AES256EncryptWithKey:(NSString *)key {
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
// fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [self length];
//See the doc: For block ciphers, the output size will always be less than or
//equal to the input size plus the size of one block.
//That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
keyPtr, kCCKeySizeAES256,
NULL /* initialization vector (optional) */,
[self bytes], dataLength, /* input */
buffer, bufferSize, /* output */
&numBytesEncrypted);
if (cryptStatus == kCCSuccess) {
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
free(buffer); //free the buffer;
return nil;
}
- (NSData *)AES256DecryptWithKey:(NSString *)key {
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
// fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [self length];
//See the doc: For block ciphers, the output size will always be less than or
//equal to the input size plus the size of one block.
//That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesDecrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
keyPtr, kCCKeySizeAES256,
NULL /* initialization vector (optional) */,
[self bytes], dataLength, /* input */
buffer, bufferSize, /* output */
&numBytesDecrypted);
if (cryptStatus == kCCSuccess) {
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
}
free(buffer); //free the buffer;
return nil;
}
@end
@interface CustomAESHelper ()
@end
@implementation CustomAESHelper
+ (NSString*) encryptString:(NSString*)plaintext withKey:(NSString*)key {
NSData *JSONData = [[plaintext dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptWithKey:key];
// Get NSString from NSData object in Base64
NSString *base64Encoded = [JSONData base64EncodedStringWithOptions:0];
// NSLog(@"encryptString = %@",base64Encoded);
// NSLog(@"encryptString = %@",[[NSString alloc] initWithData:JSONData
// encoding:NSUTF8StringEncoding]);
//
//
// NSLog(@"decryptData = %@",[self decryptData:JSONData withKey:key]);
return base64Encoded;
}
+ (NSString*) encryptNSMutableArray:(NSMutableArray *)mutableArray withKey:(NSString *)key
{
NSData *data = [[NSKeyedArchiver archivedDataWithRootObject:mutableArray]AES256EncryptWithKey:key];
// Get NSString from NSData object in Base64
NSString *base64Encoded = [data base64EncodedStringWithOptions:0];
// NSLog(@"encryptString = %@",base64Encoded);
// NSLog(@"encryptString = %@",[[NSString alloc] initWithData:JSONData
// encoding:NSUTF8StringEncoding]);
//
//
// NSLog(@"decryptData = %@",[self decryptData:JSONData withKey:key]);
return base64Encoded;
}
+ (NSString*) decryptData:(NSData*)ciphertext withKey:(NSString*)key {
return [[NSString alloc] initWithData:[ciphertext AES256DecryptWithKey:key]
encoding:NSUTF8StringEncoding] ;
}
@end
- 日志显示:
2021-05-14 12:13:06.806259-0400 MyProjects[1609:814424] subject:WLSdQGDlb2CbBtKoK/ukbYv1HOl5ZVZo9P5VRV9426GMurhKD5o7U53MfvYaLmogJCYz32s8uz4B0HxBawlph3sgfdDieA3Lxh8D4WLLXqwY2psVasukKV1HTR9Jst1cI3O/vorvheSRvBb4JZQYotmhVPsjEkSc2xJ5ewyBCL0uv3VRWwe4qhB94Q1F/EowW5s3aH9CRlf/H9hJg1ougyX1ZL02OydMrFMXCwZSALHKLT6kCase/oHTTGyuDvs8xzLk3QSBiUO2G9ppeXmRxYB/sPAFpDI8eV2T5/O+xlIP/LLE/eyKe+wEfxWlKG1uAwiVhfrHmFMueRG7Hv6DJ/s63M2o3vziB6zfX832rQc=
2021-05-14 12:13:06.809211-0400 MyProjects[1609:814424] decrypted:(null)
2021-05-14 12:13:06.809757-0400 MyProjects[1609:814424] subject:WLSdQGDlb2CbBtKoK/ukbc1429tOxdpzEE6W/leNEoWJCIzf+R7D6u+FSu1JDXgIGiF5pgh5BJQK3yNJVYxLYsaL3kpP2yL2ALPILY6WdWBA/GJFo3s6Y0rMeEh4UBkb/yDNqbZhK2hrn3e+zvFQYG6i0+rE3rhXkTlRcRWmXB0JRTg7pTt2BtNOe+CynG3SgwowYv+R/244Ab6z/Tg+ejKs41wrKCJcBsiU5Yl18oUCeiycmQYtgRoX+yz2o5X1F/arIDi2pdCBIIS1n7sII+woRL2C0o9N5YJl3zzWnF0RwxmkSPKz7j71+sHO4OIGw+tiaKPDTfQf3K0ViQezEVHO9jAxPglkcEtMm5T1A/dWSTZQv4HjAwQ8ZjmZ5Y25Qki7oQgNStyKPxHafINj8g==
2021-05-14 12:13:06.811011-0400 MyProjects[1609:814424] decrypted:(null)
是我第一次使用这种方法加密,加密方法也正常工作,我遇到的奇怪问题是解密方法,或者我做错了什么,遗漏了一些细节或其他东西,我看到了很多答案和问题,或者我怎样才能将字符串值从 JSON 转换为 NSData 作为密码数据正确?或者请问您的建议,谢谢!
更新1:
回顾一下,当我直接复制主题字符串进行解密而不解析解密方法时,decrypt方法是否正常工作:
NSString *test = @"oTd6+L9Lt/cWCMUPE1XvqSrTA9orCIPTWGNqbCw55SJzvB0mmFBqZfFI7pmqy7MdPc8AhSrFDFXsCjR6O+GOhGcYV3punTShjynSREI863449fzED7I/Y9vZFQr3CB3Hfbw/fEXfCEorCXhlI703GWOT4be68pPpayLus1bZuLXUT4iek1P/Gj94UH0GaNQJZFT8lwywZ34mzPt7YfnqK2X4Amj2ebKCx9uoEcJM5wL96yqdf1vZIhxsWO2EujcZmpMU238DhhjmqUIYUg0rk9sKHbNww41MrTZgSDutWDM67OiT5SyHZZ+Dw8VdamISjJgiyQGQkbfRzJNGKYZlacy10bSeWJrOgXo/c7UN/FDvP/QZJXvJX0pJbeP3JZRyyk8Az+xg1RAukuEcRot0AEy4tDDg2F9X5V/gfWtMVhceDvecc+SlnL5lkT2Kw8sc3Vcx/In270C+t6slxxAkLa24AnBVGEUNxMAtwCq1veBZE6FBlEVdoamE1yLstFI44Qma3a8pUQVvqw1tncadZQrRSkzYIdJTTK1xxJ1biyoG2VXlX51WCl+W6DDa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h3kbMqcnPXkIMoExj3YrWPbn/wwxCX/Ge9xS6ZEftvjk51HsZtgowhUHw/kbo1+97DaY/ABAtY6bAC4YMI8yRtH7p4YVWTEv1ZNVeFljc6JipES19VBryKtYL2wqJmm7iGuhWbnNy3OdPWnL+KK1iZKMo76IGpr5+ZFN40/HjzRjLjSsNQMenkR478Qc/q5FKLxwS8Q/ws/setT36KOZ74ZxNuuxapJtBOIUMCu0LmMhtgw0lFlRHKs2l2U4U8ZKRdYpJmRkxkjSI6bvxsQmNlkfeyd7Y2xpk1mdvxrO1cRGuvX+HjZg==";
NSData *dataTest = [[NSData alloc] initWithBase64EncodedString:test options:kNilOptions];
NSLog(@"dataTest: %@", dataTest);
NSString *decryptTest = [CustomAESHelper decryptData:dataTest withKey:secret];
NSLog(@"decryptTest: %@", decryptTest);
2021-05-15 20:33:05.424858-0400 MyProjects[2003:1228662] subject:WLSdQGDlb2CbBtKoK/ukbc1429tOxdpzEE6W/leNEoWJCIzf+R7D6u+FSu1JDXgIGiF5pgh5BJQK3yNJVYxLYsaL3kpP2yL2ALPILY6WdWBA/GJFo3s6Y0rMeEh4UBkb/yDNqbZhK2hrn3e+zvFQYG6i0+rE3rhXkTlRcRWmXB0JRTg7pTt2BtNOe+CynG3SgwowYv+R/244Ab6z/Tg+ejKs41wrKCJcBsiU5Yl18oUCeiycmQYtgRoX+yz2o5X1F/arIDi2pdCBIIS1n7sII+woRL2C0o9N5YJl3zzWnF0RwxmkSPKz7j71+sHO4OIGw+tiaKPDTfQf3K0ViQezEVHO9jAxPglkcEtMm5T1A/dWSTZQv4HjAwQ8ZjmZ5Y25Qki7oQgNStyKPxHafINj8g==
2021-05-15 20:33:05.425797-0400 MyProjects[2003:1228662] dataSubject: {length = 304, bytes = 0x58b49d40 60e56f60 9b06d2a8 2bfba46d ... 8a3f11da 7c8363f2 }
2021-05-15 20:33:05.425917-0400 MyProjects[2003:1228662] decryptSubject: (null)
2021-05-15 20:33:05.426105-0400 MyProjects[2003:1228662] dataTest: {length = 3904, bytes = 0xa1377af8 bf4bb7f7 1608c50f 1355efa9 ... 5c446baf 5fe1e366 }
2021-05-15 20:33:05.426219-0400 MyProjects[2003:1228662] decryptTest: [{"position":0,"shortName":"Dan","class":"Stakeholder","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Stakeholder\/p2","project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","rank":2,"projects":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1"]},{"position":0,"shortName":"Mark","class":"Stakeholder","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Stakeholder\/p1","project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","rank":1,"projects":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1"]},{"position":0,"project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Implication\/p2","class":"Implication","name":"aes256 decrypt","onLeft":0},{"position":0,"project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Implication\/p1","class":"Implication","name":"aes256 encrypt","onLeft":1},{"position":0,"project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Experience\/p2","class":"Experience","name":"Trying test all options","onLeft":0},{"position":0,"project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Experience\/p1","class":"Experience","name":"Test Dan code","onLeft":1},{"position":0,"task":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Task\/p2","class":"Resource","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Resource\/p2","project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","longDescription":"","type":"task","name":"Check StackOverflow"},{"resourceCollapsed":1,"position":0,"project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","dueDate":"","completed":"","type":"task","completedDate":"","resources":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Resource\/p2"],"longDescription":"","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Task\/p2","class":"Task","name":"Test new libraries","calendarReference":""},{"position":1,"task":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Task\/p1","class":"Resource","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Resource\/p1","project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","longDescription":"","type":"barrier","name":"Still trying fixing ASAP"},{"resourceCollapsed":1,"position":1,"project":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","dueDate":"","completed":"","type":"barrier","completedDate":"","resources":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Resource\/p1"],"longDescription":"","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Task\/p1","class":"Task","name":"Without success until yet","calendarReference":""},{"tasks":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Task\/p2","x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Task\/p1"],"intentions":"Test AES 256 with help of DAN","resources":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Resource\/p2","x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Resource\/p1"],"class":"Project","objectId":"x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Project\/p1","implications":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Experience\/p2","x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Experience\/p1"],"stakeholders":["x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Stakeholder\/p2","x-coredata:\/\/6ABAC2F1-A324-4CA6-8966-D410039C7626\/Stakeholder\/p1"],"date":"2021-05-14 22:16:26 +0000","name":"Test 3 AES 256","objective":"Test 3"}]
那么,从JSON数据响应中获取正确的字符串有什么帮助吗?我是否在用加密值解析 JSON 时做错了什么?
答: 暂无答案
评论
subject
NSArray
NSDictionary