For Programmers: Free Programming Magazines  


Home > Archive > Java Security > April 2005 > Getting derived key from PBE









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Getting derived key from PBE
Michel Gallant

2005-04-22, 4:01 pm

Is there any way to access the DERIVED key (say a 3DES key)
in J2SE and PBE?
I think that although the internally derived IV is accessible, the
derived key is not. Is that correct?

e.g.

String MYPBEALG = "PBEWithSHA1AndDESede" ;
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
String password = "ssshh! a difficult secret" ;
PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray());
keyFac = SecretKeyFactory.getInstance(MYPBEALG);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
Cipher pbeCipher = Cipher.getInstance(MYPBEALG);
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

byte[] IV = pbeCipher.getIV() ; //actual internally generated IV

byte[] key = pbeKey.getEncoded(); //this just returns the password as a byte[]

- Mitch


ekuleshov@gmail.com

2005-04-22, 4:01 pm

Michel Gallant wrote:
> Is there any way to access the DERIVED key (say a 3DES key)
> in J2SE and PBE?
> I think that although the internally derived IV is accessible, the
> derived key is not. Is that correct?
>
> e.g.
>
> String MYPBEALG = "PBEWithSHA1AndDESede" ;
> PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt,

count);
> String password = "ssshh! a difficult secret" ;
> PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray());
> keyFac = SecretKeyFactory.getInstance(MYPBEALG);
> SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
> Cipher pbeCipher = Cipher.getInstance(MYPBEALG);
> pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
>
> byte[] IV = pbeCipher.getIV() ; //actual internally generated IV
>
> byte[] key = pbeKey.getEncoded(); //this just returns the

password as a byte[]

There are some helper classes in BouncyCastle provider that will
return derived key params.

regards,
Eugene

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com