Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Nikolay Elenkov
On Mon, Dec 17, 2012 at 8:59 AM, Matthew Fleming wrote: > Got it. The problem was that I had replaced > > byte[] keyBytes = keyFactory.generateSecret(keySpec).getEncoded(); > > SecretKey key = new SecretKeySpec(keyBytes, "AES"); > > > with > > > SecretKey key = keyFactory.generateSecret(keySpec);

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Matthew Fleming
Got it. The problem was that I had replaced byte[] keyBytes = keyFactory.generateSecret(keySpec).getEncoded(); SecretKey key = new SecretKeySpec(keyBytes, "AES"); with SecretKey key = keyFactory.generateSecret(keySpec); This is not a problem for the generic version of the Bouncy Castle pro

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Matthew Fleming
Thanks very much. Using your code and a few other bits and pieces, I've come up with this, which generates a SecretKey for AES and then wraps it using PBE: KeyGenerator generator = KeyGenerator.getInstance("AES"); generator.init(128); Key keyToBeWrapped = generator.generateKey(); Log.v("

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Nikolay Elenkov
On Mon, Dec 17, 2012 at 1:57 AM, Matthew Fleming wrote: > Thanks very much. I had pretty much reached the same conclusion -- that I > should just try switching to encryption/decryption rather than wrap/unwrap, > and this works. I have included a complete example, below, which works on > Android 4.

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Matthew Fleming
Thanks very much. I had pretty much reached the same conclusion -- that I should just try switching to encryption/decryption rather than wrap/unwrap, and this works. I have included a complete example, below, which works on Android 4.2, 4.1, and presumably earlier versions. Actually I developed

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Nikolay Elenkov
On Sat, Dec 15, 2012 at 12:17 PM, Matthew Fleming wrote: >> >> You can also try deriving the wrap key separately with something like: >> >> KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, >> ITERATION_COUNT, KEY_LENGTH); >> SecretKeyFactory keyFactory = SecretKe

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-16 Thread Piren
does this help? http://stackoverflow.com/questions/13433529/android-4-2-broke-my-encrypt-decrypt-code-and-the-provided-solutions-dont-work On Saturday, December 15, 2012 5:17:05 AM UTC+2, Matthew Fleming wrote: > > >> You can also try deriving the wrap key separately with something like: >> >>

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-14 Thread Matthew Fleming
> > > You can also try deriving the wrap key separately with something like: > > KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, > ITERATION_COUNT, KEY_LENGTH); > SecretKeyFactory keyFactory = SecretKeyFactory > .getInstance("PBKDF2WithHm

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-13 Thread Nikolay Elenkov
On Fri, Dec 14, 2012 at 11:22 AM, Nikolay Elenkov wrote: > On Fri, Dec 14, 2012 at 11:15 AM, Matthew Fleming wrote: >> >> >> On Wednesday, December 12, 2012 11:21:10 PM UTC-6, Nikolay Elenkov wrote: >>> >>> On Thu, Dec 13, 2012 at 11:55 AM, Matthew Fleming >>> wrote: >>> > I use the following co

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-13 Thread Nikolay Elenkov
On Fri, Dec 14, 2012 at 11:15 AM, Matthew Fleming wrote: > > > On Wednesday, December 12, 2012 11:21:10 PM UTC-6, Nikolay Elenkov wrote: >> >> On Thu, Dec 13, 2012 at 11:55 AM, Matthew Fleming >> wrote: >> > I use the following code to encrypt a SecretKey with password-based >> > encryption: >> >

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-13 Thread Matthew Fleming
On Wednesday, December 12, 2012 11:21:10 PM UTC-6, Nikolay Elenkov wrote: > > On Thu, Dec 13, 2012 at 11:55 AM, Matthew Fleming > > > wrote: > > I use the following code to encrypt a SecretKey with password-based > > encryption: > > > > Cipher pbeEncryptCipher = Cipher.getInstance("PBEWithM

Re: [android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-12 Thread Nikolay Elenkov
On Thu, Dec 13, 2012 at 11:55 AM, Matthew Fleming wrote: > I use the following code to encrypt a SecretKey with password-based > encryption: > > Cipher pbeEncryptCipher = Cipher.getInstance("PBEWithMD5AndDES"); Try Cipher.getInstance("PBEWithMD5AndDES", "BC"); Also probably not a good idea to

[android-developers] Cipher.wrap() not working in Android 4.2?

2012-12-12 Thread Matthew Fleming
I use the following code to encrypt a SecretKey with password-based encryption: Cipher pbeEncryptCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeEncryptCipher.init(Cipher.WRAP_MODE, pbeKey, pbeParamSpec); byte[] symKeyBytes = null; try { symKeyBytes = pbeEncryp