import org.apache.commons.codec.binary.Base64; /** * * @author Meihta Dwiguna Saputra */ public class Main { public static void main(String[] args) { String name = "Meihta Dwiguna Saputra"; String encodeResult = new Main().encodeBase64(name); String decodeResult = new Main().decodeBase64(encodeResult); System.out.println("Encode Result = " + encodeResult); System.out.println("Decode Result = " + decodeResult); } private String encodeBase64(String stringToEncode) { return Base64.encodeBase64String(stringToEncode.getBytes()); } private String decodeBase64(String base64ToDecode) { return new String(Base64.decodeBase64(base64ToDecode.getBytes())); } }
Here is result if we run the program :
NB : You need apache common-codec library to use code above, also if you found exception or error, do not worry, it means the library have dependency injection from another apache library, by find and add dependency injection it should be work properly. 😉
Pilus Lumbantoruan
Oct 21, 2011 @ 11:33:13
knp harus bhs inggris ta blog nya …. tidak cinta indonesia ah ente … ckckckck
captain_kuro
Oct 21, 2011 @ 16:51:09
Judulnya encrypt-decrypt tapi kodenya encode-decode?
Meihta Dwiguna Saputra
Oct 21, 2011 @ 17:33:31
my mistake wil, awak kira encryption = encode
setelah googling ternyata :
* Encryption = encipherment = make secret
* Encoding = to convert format, not necessarily securely
thanks for correcting 😉