Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / August 2005

Tip: Looking for answers? Try searching our database.

JCE - load key from string

Thread view: 
chermisha@yahoo.com - 09 Aug 2005 16:08 GMT
Hi All,

We're trying to use JCE to encrypt some data. The issue is key storage.
We want to store it in some database, so the question is how to
re-create the key for decryption from varchar2 column?

The key in string form looks like this:

cryptix.jce.provider.key.RawSecretKey@3bfce353

This can be stored in the database easily. But how to load this into
KeyStore back?

TIA
Michael
Ben_ - 09 Aug 2005 20:15 GMT
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... :-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.