gpt4 book ai didi

objective-c - CCCrypt 解密结果为 -4304

转载 作者:行者123 更新时间:2023-11-29 13:32:48 25 4
gpt4 key购买 nike

当我加密一个字符串然后立即解密时,CCCryptorStatus 为 -4304 并且生成的解码字符串长度不正确。谁能看出我可能做错了什么?

//Encrypt

NSString *plainText = @"e22ae25e-0b20-433a-8aa5-a5678714f590";
NSData *rawData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
size_t outLength;
NSMutableData *cipherData = [NSMutableData dataWithLength:rawData.length + kCCBlockSizeAES128];
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, [AESKey bytes], [AESKey length], NULL, [rawData bytes], [rawData length], [cipherData mutableBytes], [cipherData length], &outLength);

//[plainText length] = 36
//[rawData length] = 36
//[cipherData length] = 52
//outLength = 48

//Decrypt

NSMutableData *decodedData = [NSMutableData dataWithLength:cipherData.length + kCCBlockSizeAES128];

//[decodedData length] = 68

CCCryptorStatus cryptStatus2 = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, [AESKey bytes], [AESKey length], NULL, [cipherData bytes], [cipherData length], [decodedData mutableBytes], [decodedData length], &outLength);
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];

//[decodedData length] = 68
//[decodedString length] = 68

/*
At this point, cryptStatus2 is -4304 and
decodedString = "e22ae25e-0b20-433a-8aa5-a5678714f590\f\f\f\f\f\f\f\f\f\f\f\f";

*/

最佳答案

根据头文件,这是一个kCCAlignmentError。尝试使用 outlength 而不是 [cipherData length]

关于objective-c - CCCrypt 解密结果为 -4304,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11437995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com