This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Convertion between SecretKey to String or byte Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convertion between SecretKey to String or byte" Watch "Convertion between SecretKey to String or byte" New topic
Author

Convertion between SecretKey to String or byte

R.Lakshmi Narasimhan
Greenhorn

Joined: Feb 02, 2009
Posts: 5
Hi.I am not so good in Java. I need to know how to convert a DES SecretKey generated using Java to a String and vice versa. I am doing a program in java using DES. It is needed to convert the SecretKey (which is for encryption) to String and has to be sent to another process and in there, the same SecretKey has to be got from Srting (for Decryption).Please help me.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Welcome to JavaRanch.

You can obtain the bytes that make up the key by calling its getEncoded method. Using a reversible encoding like base-64 it is possible to create a String from that (and later transform it back into a byte[]).

A base-64 encoder/decoder can be found at http://www.source-code.biz/snippets/java/Base64Coder.java.txt


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: Convertion between SecretKey to String or byte