我正在尝试解密使用 AES 256 CFB 模式在 Python 中加密的文件。
当我尝试在 IOS 中解密它时,它无法解密它。给一些垃圾字符串。
NSString * AES_Decrypt(NSString * key, NSString * cipherText,NSString *iv)
{
@autoreleasepool {
NSMutableData * mutableCipher = [[NSMutableData alloc] init];
mutableCipher = (NSMutableData *)[cipherText dataUsingEncoding:NSUTF8StringEncoding];
char keyPtr[kCCKeySizeAES256+1];
bzero( keyPtr, sizeof(keyPtr) );
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSASCIIStringEncoding];
uint8_t iv[kCCKeySizeAES128+1];
bzero((void *) iv, (size_t) sizeof(iv));
size_t numBytesEncrypted = 0;
NSUInteger dataLength = [mutableCipher length];
size_t bufferSize = dataLength + kCCKeySizeAES128;
void *buffer_decrypt = malloc(bufferSize);
NSMutableData * output_decrypt = [[NSMutableData alloc] init];
CCCryptorStatus result = CCCrypt(kCCDecrypt , kCCAlgorithmAES128, kCCModeCFB, keyPtr, kCCKeySizeAES128, iv, [mutableCipher mutableBytes] , [mutableCipher length], buffer_decrypt, bufferSize, &numBytesEncrypted);
output_decrypt = [NSMutableData dataWithBytesNoCopy:buffer_decrypt length:numBytesEncrypted];
NSString * decryptedStr = [[NSString alloc] initWithData:output_decrypt encoding:NSASCIIStringEncoding];
NSLog(@"Decrypted String is::%@",decryptedStr);
if(result == kCCSuccess){
return decryptedStr;
}
else{
return NULL;
}
}
return NULL;
}
我用以下参数调用它。
AES_Decrypt(@"d5a75c3377fbd50a24ae372c787d598b633e82f4210f90dfc8e618c47811d812", @"”l*®*ŸÂ€Û»†.Sì’±—ë", @"3d396f81a3443ca44ce146c91a81d3d8");
但是该方法的输出没有返回预期的输出。谁能帮我这个。