Pages

Ads 468x60px

Sunday, July 22, 2012

Java: Simple Encoding/Decoding

This program can be used for basic encoding and decoding of data. It uses commons-codec-1.6.jar and you can download it from the following link: http://mvnrepository.com/artifact/commons-codec/commons-codec/1.6





import org.apache.commons.codec.binary.Base64;

// to encode and decode information
public class CryptInfo {

// encode a text
public String encode(String text) {

byte[] encoded = Base64.encodeBase64(text.getBytes());
return new String(encoded);
}

//decode a text
public String decode(String text) {

byte[] decoded = Base64.decodeBase64(text);
return new String(decoded);
}
}

No comments:

Post a Comment