Hello,
Most samples you'll find store the key in a file. It's as simple as new
ObjectOutputStream(new FileOutputStream(file)).writeObject(key).
Now, you want to save a string into a database.
So you'd need to serialize the object into a ByteArrayOutputStream, convert
the bytes with Base64 and save the resulting string. And the other way round
to load it.
Just out of my head, not verified... :-)
chermisha@yahoo.com - 10 Aug 2005 18:14 GMT
Hi Ben,
Yes, I know how to create key from file :-)
The solution I found looks like this (example is for TripleDES
encryption
key):
DESedeKeySpec desKeySpec = new DESedeKeySpec("[24-bit key
string]".getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(desKeySpec);
This way the key is restored correctly. I think your solution works
too, but
I haven't tried it - I'm not sure it's any smaller or quicker?...
Thanks a lot
Michael
chermisha@yahoo.com - 10 Aug 2005 18:16 GMT
Hi Ben,
Yes, I know how to create key from file :-)
The solution I found looks like this (example is for TripleDES
encryption
key):
DESedeKeySpec desKeySpec = new DESedeKeySpec("[24-bit key
string]".getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(desKeySpec);
This way the key is restored correctly. I think your solution works
too, but
I haven't tried it - I'm not sure it's any smaller or quicker?...
Thanks a lot
Michael
> Hello,
>
[quoted text clipped - 8 lines]
>
> Just out of my head, not verified... :-)