Friday, March 17, 2017

Java encode and decode a string

static String decodepassword = "aGFwcHltYW4xNjM=";
static String encodepassword = "happyman163";

public static void main(String[] args) {
System.out.println(getEncodedpassword());
System.out.println(getDecodedpassword());
}

public static String getDecodedpassword() {
return new String(Base64.getDecoder().decode(decodepassword.getBytes()));
}

public static String getEncodedpassword() {
return new String(Base64.getEncoder().encode(encodepassword.getBytes()));
}