Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Champioshere opened this issue Sep 8, 2015 · 6 comments

Comments

@Champioshere
Copy link

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

  • (NSString_) encryptString:(NSString_)XMLRequest withKey:(NSString *)key
    {
    NSData * encryptedData = [[StringEncryption alloc] encrypt:[XMLRequest dataUsingEncoding:NSUTF8StringEncoding] key:key iv:IV];
    NSString * encryptedXML = [encryptedData base64EncodingWithLineLength:0];

     return encryptedXML;
    

    }

//decrypt

  • (NSData_) decryptData:(NSData_)XMLResponse withKey:(NSString *)key
    {
    NSString *responseString = [[NSString alloc] initWithData:XMLResponse encoding:NSUTF8StringEncoding];
    NSLog(@"responseString--------------------------%@",responseString);

    //

    NSData * decryptedData = [[StringEncryption alloc] decrypt:XMLResponse key:key iv:IV];

    //

    NSString * decryptedXML = [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding];
    NSLog(@"decrypted data:: %@", decryptedXML);

    return decryptedData;
    // this data sent for xml parsing
    }

@Champioshere
Copy link
Author

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
Copy link
Author

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.

@Champioshere Champioshere changed the title "Bad padding exception: Given Final Block Not Properly Padded" error at JAVA server for iOS Project but working fine in Android. Decryption is not working on iOS but working fine in Android and Java server. Sep 11, 2015
@dowi
Copy link

dowi commented Oct 9, 2015

is there an update for this issue?

thanks a lot!

@giaesp
Copy link

giaesp commented Dec 10, 2015

@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
Copy link

MVakas commented Feb 3, 2016

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants