Never convert the binary byte[] (encrypted_password) into String.
You can use key.getEncoded() which prints an encoded string. Save it in
the
database.
When you read the string, you can create the keyspecification using
EncodedKeySpec(byte[] encodedKey)
And Then, use SecretKeyFactory.generateSecret(KeySpec .....) to derive at
the Key.
Thanks,
Selva-
InfoTekies Cor****ation.
<iszekeell@[EMAIL PROTECTED]
> wrote in message
news:1178135700.773704.281480@[EMAIL PROTECTED]
> ok
> so I'm trying to store a key for late for later use with a password
> and i can get as far as saving and retrieving it. but can't use it
> again
> this is what i have:
>
> KeyGenerator kg = KeyGenerator.getInstance("DES");
> Key key = kg.generateKey();
> Cipher cipher = Cipher.getInstance("DES");
>
> cipher.init(Cipher.ENCRYPT_MODE,key);
> byte[] encrypted_password = cipher.doFinal(password.getBytes());
> JOptionPane.showMessageDialog(null,"Encrypted Password "+ new
> String(encrypted_password));
>
> String coughtPassword = new String(encrypted_password);
>
> cipher.init(Cipher.WRAP_MODE,key);
> byte[] keyAsByte = cipher.wrap(key);
> String keyAsString = new String(keyAsByte);
>
> //coughtpassword and keyAsString are save in mySql by a Dao
>
> // the piece i have been unable to do is here i want to reconstruct
> keyAsString into the workable key2
> //any suggestions are welcome
>
> cipher.init(Cipher.DECRYPT_MODE,key2);
> byte[] decrypted_password2 =
> cipher.doFinal(coughtPassword.getBytes());
> JOptionPane.showMessageDialog(null,"Decrypted Password "+new
> String(decrypted_password2));
>


|