[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: Encoding



Here's some code that should help you out.
It's only bits and pieces but should be enough to help you out.
If you want to pass in a string, you can do that instead, and use the
getBytes() method to get a byte array.

    import javax.crypto.Cipher;
 
    // encrypt a byte array with encryption key
     public String encrypt(byte[] clearText, SecretKey encryptKey)
     {
      byte[] cipherText = null;
      String encryptedString = null;

      try
      {
       desCipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
//DESede (tripleDes)
       desCipher.init(Cipher.ENCRYPT_MODE, encryptKey);
       // encrypt the string (byte array)
       cipherText = desCipher.doFinal(clearText);
       // create a string from the byte array		
       encryptedString = new String( desCipher );
      }
      catch( blah blah blah )
      {  // do error stuff here  }

      return encryptedString;


Thanks,
Frank Merenda
Senior Software Engineer
AtWork Technologies, Inc.
fmerenda@atwork.com 




-----Original Message-----
From: Deron Pardue [mailto:dpardue@dspin.com]
Sent: Tuesday, September 18, 2001 2:58 PM
To: ajug-members@www.ajug.org
Subject: Encoding


I have an encrypted string (using Triple DES) that I need to set as a
cookie.  In order for this to work, I think I need to UUEncode it or use
a Base64 encoding.  The problem is that all of the examples I can find
take and produce InputStreams and OutputStreams.  I just need to pass a
String into it and get an encoded String out.  How do I do this?

Thanks!

Deron Pardue