Monday, November 25, 2013

[android-developers] Android 4.4 Encryption Code Not Backwards Compatible

Since 4.4 my encryption code (working since Android 1.5) fails with...

java.security.InvalidKeyException: initialisation vector must be the same length as block size

....at the init call in the following code:

            String passphrase = "pass";
            String alg = "PBEWITHSHA-256AND256BITAES-CBC-BC";
           
            PBEKeySpec keySpec = new PBEKeySpec( passphrase.toCharArray(), salt, 2001 );

            SecretKey key =  SecretKeyFactory.getInstance( alg ).generateSecret( keySpec );
           
            Cipher ecipher = Cipher.getInstance( key.getAlgorithm() );

            AlgorithmParameterSpec paramSpec = new IvParameterSpec( initVector );

            ecipher.init( Cipher.ENCRYPT_MODE, key, paramSpec );

initVector and salt are both 8 byte arrays.

ecipher.getBlockSize() reports 16, so yes, it doesn't match the initialization vector.

Presumably some default has changed somewhere.

This leaves all my users who used encryption in any way completely stuck.

I've tried to arrange without success that the cipher block size is set to 8.

For instance:

Cipher.getInstance( "AES/CBC8/PKCS5Padding" );

Gives:

java.security.NoSuchAlgorithmException: can't support mode CBC8

On the other hand, making initVector a 16 byte array causes init() to throw:

java.security.InvalidKeyException: invalid parameter passed to AES init - com.android.org.bouncycastle.crypto.params.ParametersWithIV

Any ideas ?

TIA,

Pent

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate