skavinvarnan / Cross-Platform-AES

Simple cross-platform encryption and decryption using AES
MIT License
142 stars 69 forks source link

Decryption not working on IOS 13 #29

Closed ahsanghauri closed 5 years ago

ahsanghauri commented 5 years ago

decryption work fine pervious version but not working on IOS 13.please help

janibekm commented 5 years ago

mytext: 1234 crypto: LXY1ElqyWvsPV+YaRf6FdoY3GNUbijO4bKUwlcJTmuA= decrypt: cannot decrypt key: mykey cannot decrypting , in ios13, xcode 11, macos catalina, Please help.

mrazam110 commented 5 years ago

same issue

Zeeshan03422 commented 5 years ago

same issue decryption not working on IOS 13

skavinvarnan commented 5 years ago

Will look into it

squshipillow commented 5 years ago

I am having the same problem just started to debug. It is not refreshing the encryption on login. I will let you know if I find anything out

squshipillow commented 5 years ago

I have partially gone through apples code and have not seen any major changes to the lib as of yet. I did change a little code in order to get a new encrypted password each time, which wasn't working properly. My server has been throwing Errors only on Xcode 11 builds so it is clearly something in Xcode11.

ghost commented 5 years ago

The sha256 for the same key on iOS12 and iOS13 are different, the problem could be somewhere there. The return value for CryptLib().sha256("placeholderKey", length: 32) is

felipembassi commented 5 years ago

@skavinvarnan @Farcvel @squshipillow @ahsankhatri

Inside: - (NSString*) sha256:(NSString *)key length:(NSInteger) length

I replaced NSString *hash=[out description]; To NSString *hash=[out debugDescription];

And everything got back to normal

31

squshipillow commented 5 years ago

worked for me, awesome!

ahsanghauri commented 5 years ago

@skavinvarnan @Farcvel @squshipillow @ahsankhatri

Inside: - (NSString*) sha256:(NSString *)key length:(NSInteger) length

I replaced NSString *hash=[out description]; To NSString *hash=[out debugDescription];

And everything got back to normal

31

thanks man work fine now

dm-manu commented 5 years ago

@skavinvarnan @ahsankhatri

I have found another issue with the decryption method -decryptCipherText: key : iv:

`- (NSString ) decryptCipherText:(NSString )ciperText key:(NSString )key iv:(NSString )iv {

return [[NSString alloc] initWithData:[[CryptLib alloc] decrypt:[[NSData alloc] initWithBase64EncodedString:ciperText options:NSDataBase64DecodingIgnoreUnknownCharacters] key:[[CryptLib alloc] sha256:key length:32] iv:[[CryptLib alloc] generateRandomIV16]] encoding:NSUTF8StringEncoding];

}

Please see that the above method does not use the given argument for iv and it generates a random IV instead. This will also results invalid result while decrypting data. Please look into this and kindly change accordingly.

Thanks in advance.

senthilhisto commented 5 years ago

Refer below link. https://stackoverflow.com/questions/58098958/aes-encryption-cryptlib-in-ios-13-not-working You can use for nsdata to hex conversion below

pragma mark - String Conversion

-(NSString)hex:(NSData)data{ NSMutableData result = [NSMutableData dataWithLength:2data.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];

}

octalanil1 commented 5 years ago
KamilFaheem-1994 commented 4 years ago

debugDescription

Work for me (thanks)

devendrayadav9 commented 4 years ago

@skavinvarnan @Farcvel @squshipillow @ahsankhatri Inside: - (NSString*) sha256:(NSString *)key length:(NSInteger) length I replaced NSString *hash=[out description]; To NSString *hash=[out debugDescription]; And everything got back to normal

31

thanks you man work fine now

`NSString *hash=[out debugDescription];

devendrayadav9 commented 4 years ago

Inside: