/**
* Encode a string using Base64 encoding. Used when storing passwords
* as cookies.
*
* This is weak encoding in that anyone can use the decodeString
* routine to reverse the encoding.
*
* @param str
* @return String
*/
public static String encodeString(String str) {
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
return encoder.encodeBuffer(str.getBytes()).trim();
}
/**
* Decode a string using Base64 encoding.
*
* @param str
* @return String
*/
public static String decodeString(String str) {
sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
try {
return new String(dec.decodeBuffer(str));
} catch (IOException io) {
throw new RuntimeException(io.getMessage(), io.getCause());
}
}