If I remove the kCCOptionPKCS7Padding, the following function will return me correct buffer size with empty cipher data <>. I can't use kCCDecrypt option to decrypt empty cipher text back to Plain text.
char keyPtr[kCCKeySizeAES128 + 1];
memset(keyPtr, 0, sizeof(keyPtr));
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
char ivPtr[kCCBlockSizeAES128 + 1];
memset(ivPtr, 0, sizeof(ivPtr));
[iv getCString:ivPtr
maxLength:sizeof(ivPtr)
encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [self length];
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesCrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
kCCAlgorithmAES128,
kCCOptionECBMode|kCCOptionPKCS7Padding,
keyPtr,
kCCBlockSizeAES128,
ivPtr,
[self bytes],
dataLength,
buffer,
bufferSize,
&numBytesCrypted);
return [NSData dataWithBytesNoCopy:buffer length:numBytesCrypted];
If kCCOptionPKCS7Padding not there, encryption engine doesn't work. Thus, it looks like compulsory, not option.
My question:
Who to make CCCrypt() works without PKCS7 Padding?