import org.apache.catalina.util.Base64;
public class Base64Example {
public static void main(String[] args) {
byte[] namePass = "snoopy:snoopass".getBytes();
byte[] encoding = Base64.encode(namePass);
byte[] decoding = Base64.decode(encoding);
String decodedStr = new String(decoding);
String name = decodedStr.substring(0, decodedStr.indexOf(":"));
String password = decodedStr.substring(decodedStr.indexOf(":") + 1,
decodedStr.length());
System.out.println("Decoding: " + new String(encoding));
System.out.println("Name: " + name + " Password: " + password);
}
}
|