Closed tselvakumar30 closed 4 years ago
Same. The fix for #29 worked but when I'm sending data from iOS 13 (fixed) to iOS 11 (pre-fixed) version, iOS 11 (the pre-fixed version) crashes.
Breakpointing, I can see that status == kCCSuccess, but the returned data is (null)
I managed to fix it by doing the alternative approach here.
use this function and replace NSString *hash=[out debugDescription];
with NSString *hash = [self hex: out];
-(NSString*)hex:(NSData*)data{
NSMutableData *result = [NSMutableData dataWithLength:2*data.length];
unsigned const char* src = data.bytes;
unsigned char* dst = result.mutableBytes;
unsigned char t0, t1;
for (int i = 0; i < data.length; i ++ ) {
t0 = src[i] >> 4;
t1 = src[i] & 0x0F;
dst[i*2] = 48 + t0 + (t0 / 10) * 39;
dst[i*2+1] = 48 + t1 + (t1 / 10) * 39;
}
return [[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding];
}
I'm still on testing phase but the results so far looks positive.
This issue has been fixed
Hi I have used the following method to encrypt
(NSData )encrypt:(NSData )plainText key:(NSString )key iv:(NSString )iv { char keyPointer[kCCKeySizeAES256+2],// room for terminator (unused) ref: https://devforums.apple.com/message/876053#876053 ivPointer[kCCBlockSizeAES128+2]; BOOL patchNeeded; bzero(keyPointer, sizeof(keyPointer)); // fill with zeroes for padding
patchNeeded= ([key length] > kCCKeySizeAES256+1); if(patchNeeded) { NSLog(@"Key length is longer %lu", (unsigned long)[[self md5:key] length]); key = [key substringToIndex:kCCKeySizeAES256]; // Ensure that the key isn't longer than what's needed (kCCKeySizeAES256) }
//NSLog(@"md5 :%@", key); [key getCString:keyPointer maxLength:sizeof(keyPointer) encoding:NSUTF8StringEncoding]; [iv getCString:ivPointer maxLength:sizeof(ivPointer) encoding:NSUTF8StringEncoding];
if (patchNeeded) { keyPointer[0] = '\0'; // Previous iOS version than iOS7 set the first char to '\0' if the key was longer than kCCKeySizeAES256 }
NSUInteger dataLength = [plainText length];
//see https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/CCryptorCreateFromData.3cc.html // For block ciphers, the output size will always be less than or equal to the input size plus the size of one block. size_t buffSize = dataLength + kCCBlockSizeAES128; void *buff = malloc(buffSize);
size_t numBytesEncrypted = 0; //refer to http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/CommonCrypto/CommonCryptor.h //for details on this function //Stateless, one-shot encrypt or decrypt operation. CCCryptorStatus status = CCCrypt(kCCEncrypt, / kCCEncrypt, etc. / kCCAlgorithmAES128, / kCCAlgorithmAES128, etc. / kCCOptionPKCS7Padding, / kCCOptionPKCS7Padding, etc. / keyPointer, kCCKeySizeAES256, / key and its length / ivPointer, / initialization vector - use random IV everytime / [plainText bytes], [plainText length], / input / buff, buffSize,/ data RETURNED here / &numBytesEncrypted); if (status == kCCSuccess) { return [NSData dataWithBytesNoCopy:buff length:numBytesEncrypted]; }
free(buff); return nil; }
And Decrypt it using the following method,
char keyPointer[kCCKeySizeAES256+2], ivPointer[kCCBlockSizeAES128+2]; BOOL patchNeeded;
But the decryption is not working. Please help me resolve this issue.