I'm trying to decrypt using the following function, but I keep getting the same encrypted string.
What would be the reason for this?
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
const void *vEncryptedText = [data bytes];
size_t encryptedTextBufferSize = [data length];
CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t movedBytes = 0;
bufferPtrSize = (encryptedTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);
const void *vkey = (const void *) [@"123456789012345678901234" UTF8String];
ccStatus = CCCrypt(kCCDecrypt,
kCCAlgorithm3DES,
kCCOptionECBMode | kCCOptionPKCS7Padding,
vkey,
kCCKeySize3DES,
NULL,
vEncryptedText,
encryptedTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);
NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];
return [myData base64EncodedStringWithOptions:0];
Update:
I've changed data to:
NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:0];
Still no luck. I'm getting the same output string as the input encrypted string.
I've solved the issue by returning:
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];