我想解密使用AES 256 CFB模式在Python中加密的文件。AES加密interopbility IOS和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");
但該方法的輸出沒有返回預期的輸出。誰能幫我這個。
我們已經嘗試過在這裏使用ASCII。 mutableCipher =(NSMutableData *)[cipherText dataUsingEncoding:NSUTF8StringEncoding]; – user2414445