When I decrypt, there will be a decryption exception due to multiple version judgments.
but,Remove the version judgment and normal results will be displayed.
(Encrypted data & key & iv Encrypted data all identical)
Encrypted Data from [NSUserDefaults standardUserDefaults]
================================================================
Func:
Step1:
NSData* theData = [[[NSData alloc] initWithBase64EncodedString:userID options:NSDataBase64DecodingIgnoreUnknownCharacters]AES128DecryptWithKey: KEY withIV: IV];
Step2:
- (NSData *) AES128DecryptWithKey: (NSString *) _sKey withIV: (unsigned int) _iv {
char keyPtr[kCCKeySizeAES128 + 1];
bzero(keyPtr, sizeof(keyPtr));
[_sKey getCString: keyPtr maxLength: sizeof(keyPtr) encoding: NSUTF8StringEncoding];
NSUInteger dataLength = [self length];
NSData *nsData;
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
void *iv = malloc(16);
memset((void *)iv, _iv, 16);
size_t numBytesDecrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt( kCCDecrypt,
kCCAlgorithmAES128,
kCCOptionPKCS7Padding,
keyPtr,
kCCKeySizeAES128,
iv ,
[self bytes], dataLength,
buffer, bufferSize,
&numBytesDecrypted);
if (cryptStatus == kCCSuccess)
nsData = [NSData dataWithBytes: buffer length: numBytesDecrypted];
free(iv);
free(buffer);
return nsData;
}
================================================================
Xcode Ver : 11.3
Test device : SimPhone 11~13 & Iphone 6(Ver.11)、IphoneXs(Ver.13)