PKCS5Padding vs PKCS7Padding Compatability Android iOS

1k views Asked by At

I am creating both an Android and iOS version of an app and have a piece of data that needs to be encrypted. I am using the JNCryptor/RNCryptor libraries for Android and iOS respectively because they are claimed to be compatible.

However, when I encrypt with Android, my encrypted key is 114 characters long, whereas with iOS it is 112 characters long. The only difference I noticed between the two library source codes is that Android uses PKCS5Padding whereas iOS uses PKCS7Padding. Is this significant, considering that the two libraries are apparently supposed to be compatible? If so, how do I go about changing this to make the two encrypted strings of equal length?

EDIT: Android Code:

    JNCryptor cryptor = new AES256JNCryptor();
    byte[] plaintext = data.getBytes();
    String password = key;
    String a;
    try {
        byte[] ciphertext = cryptor.encryptData(plaintext, password.toCharArray());

        a = Base64.encodeToString(ciphertext, Base64.DEFAULT);

       return a;


    } catch (CryptorException e) {
        // Something went wrong
        e.printStackTrace();

        return "0";
    }

iOS Code:

NSData *data = [@"mystring" dataUsingEncoding:NSUTF8StringEncoding];



NSError *error;

NSData *encryptedData = [RNEncryptor encryptData:data

                                    withSettings:kRNCryptorAES256Settings

                                        password:DEV_AES_KEY

                                           error:&error];



NSString *myotherstring = [encryptedData base64EncodedStringWithOptions:0];

Or did you mean to compare the two libraries? These are available here: https://github.com/RNCryptor/JNCryptor

0

There are 0 answers