我目前使用的iOS上的三重DES解密如下:三重DES解密iOS中
NSString* plainText = @"My Text";
NSString* keyText = @"cf6f1ed3bf0a156e";
NSData *plainData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
NSData *keyData = [keyText dataUsingEncoding:NSUTF8StringEncoding];
size_t bufferSize = plainData.length + kCCBlockSize3DES;
NSMutableData *cypherData = [NSMutableData dataWithLength:bufferSize];
size_t movedBytes = 0;
CCCryptorStatus ccStatus;
ccStatus = CCCrypt(kCCDecrypt,
kCCAlgorithm3DES,
kCCOptionECBMode,
keyData.bytes,
kCCBlockSize3DES,
NULL,
plainData.bytes,
plainData.length,
cypherData.mutableBytes,
cypherData.length,
&movedBytes);
cypherData.length = movedBytes;
if(ccStatus == kCCSuccess) {
NSLog(@"Data: %@",cypherData);
NSLog(@"Data encoded string: %@",[NSString stringWithUTF8String:[cypherData bytes]]);
NSLog(@"Data encoded: %@",[[NSString alloc] initWithData:cypherData encoding:NSUTF8StringEncoding]);
} else {
NSLog(@"Failed DES decrypt ...");
return nil;
}
不過,我不斷收到在控制檯以下:
數據: 數據編碼的字符串:(null) 數據編碼:(null)
有關爲何發生這種情況的任何想法?任何人都可以看到任何可能的問題與此代碼?
從來沒有想過鑰匙是一個問題。謝謝您的幫助 – user481610