navneet83 / Cross-platform-AES-encryption

Basic cross platform AES encryption
Apache License 2.0
320 stars 152 forks source link

Decryption is not working on iOS but working fine in Android and Java server. #24

Open Champioshere opened 9 years ago

Champioshere commented 9 years ago

Hi, I'm using this library in iOS App, as well as our Android team, but at Java server its receiving the encrypted request, but when they decrypt it, its getting error "Bad padding exception: Given Final Block Not Properly Padded", but its working fine on Android. I'm also getting a response, but the data is not Decrypting. And at Android its working fine as they use same android code on Java servers. But it's not supporting me, can you kindly help me with it. Thanks,

Same IV and key using at JAVA server,android and IOS [hardcoded for testing]. NSString* const IV = @"288dca8258b1dd7c"; NSString* const key = @"c292a6e6c19b7403cd87949d0ad45021";

My approach as in CryptLib.m

//encrypt

//decrypt

Champioshere commented 9 years ago

HI, previously we use 44 char key but now changed to 32 char key now JAVA server receiving successful request from me and i'm received response but its not decrypting please kindly help me on this.

The Response after decrypting by using NSString * decryptedXML = [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding]; is NULL

Champioshere commented 9 years ago

Encrypted data: Ud87sgVUwOqvv3Z+zHvzNsHXUTFx6Qn3eC8Xf1/zwLXu+C6PuqGwhgCZcS27wAEzF3loG5PdnVUvyleTiBDk2/aQ537GSyuhfk/c0Ktlkc0Xi+rCYZRB18PldqjFh+laj1DSw5arnwyuO6ZCh25A/o7ObRAIOQIyp1X7bBu5oQjpyc/t7yAInljjHPYTF19ILgWaHG0O1MX4C/lMcZ/wyBEBMTkl6DKSLteaGE2qTJZq9w6PYd94RgNoyTC5rojsIX8gAVuhL8B7UNv+xb1K9paAWMaRwayyoVuqzkFSlJfHUd6FCNR/cLkwAa6/5nhuAlrqL StringEncryption* sr = [[StringEncryption alloc]init]; NSData* decryptedData = [sr decrypt:XMLResponse key:key iv:IV]; NSLog(@"%@-hh",[NSString base64StringFromData:decryptedData length:[decryptedData length]] );

I used this then my decrypted data is something like this

Decrypted Data: cGzxHE4aw+b4rEHEvbwwy7ERHwJJ65OVqfokzUxqWsrUWFZx1pUBJiP0St5MLBJoq5ekIiEzqN22Tdz5HjepqTyyAXWV2ZqKQC0dAfFqrCGkTiepFic2Wneb/0lf3iLCcTLpZAkD7sn9EO8TU4c6a943BQB6OVvjDbAsVbB9HQIIOXVWGjZmFydaY0pJ7Vy/yCoVf4Pk0wEqeSsn/LU/6yOSi/mjk1i9OrRnJtixPVPFkegRKzEtv1Gp6DeVvjXRxS1AoW+HbLs9Upn3rxF6PuHxIX1+wUs/bmLIhTrWA1+WqPv59GXXO0g3A5U/38A-hh

Can You Please help me on this As i'm using same IV and key at JAVA server,android and IOS [hardcoded for testing]. 32 char key 16 char iv and SAME key and iv for encryption and decryption. -The decryption working fine in android with same response that i received.

dowi commented 9 years ago

is there an update for this issue?

thanks a lot!

giaesp commented 8 years ago

@Champioshere did you use c# sample code contained in HowToUse.cs for Java porting? I had a very similar (probably the same) padding exception in my c# decryption code (I was trying to decrypt some Android strings) and I noticed that c# sample code has a type. Take a look at issue #31 .

MVakas commented 8 years ago

I’m having the same issue. My encryption and decryption working fine for Android and dot net but for iOS I’m having different values.

thejeff77 commented 8 years ago

Try using a 32 byte IV? This is how AES encryption works generally - in 32 byte increments.