Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Security > Re: I want to s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 8 Topic 1694 of 1825
Post > Topic >>

Re: I want to save a Key in Mysql as String

by "x x" <x@[EMAIL PROTECTED] > May 4, 2007 at 01:26 AM

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));
>
 




 8 Posts in Topic:
I want to save a Key in Mysql as String
iszekeell@[EMAIL PROTECTE  2007-05-02 12:55:00 
Re: I want to save a Key in Mysql as String
"x x" <x@[EM  2007-05-04 01:26:03 
Re: I want to save a Key in Mysql as String
Mike Amling <nospam@[E  2007-05-04 16:32:59 
Re: I want to save a Key in Mysql as String
iszekeell@[EMAIL PROTECTE  2007-05-09 10:55:14 
Re: I want to save a Key in Mysql as String
Mike Amling <nospam@[E  2007-05-10 13:32:34 
Re: I want to save a Key in Mysql as String
Mike Amling <nospam@[E  2007-05-10 18:05:03 
Re: I want to save a Key in Mysql as String
iszekeell@[EMAIL PROTECTE  2007-05-10 12:58:31 
Re: I want to save a Key in Mysql as String
iszekeell@[EMAIL PROTECTE  2007-05-10 13:06:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 10:38:35 CDT 2008.