jdk自带base64加密的使用
public static void base64(String s) {
try {
BASE64Encoder encoder = new BASE64Encoder();
String encode = encoder.encode(s.getBytes());
System.out.println("encode: " + encode);
BASE64Decoder decoder = new BASE64Decoder();
String decode = new String(decoder.decodeBuffer(encode));
System.out.println("decode: " + decode);
} catch (IOException e) {
e.printStackTrace();
}
}
jdk自带sha加密
public static void sha(String s) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA");
System.out.println(Hex.encodeHexString(digest.digest(s.getBytes())));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
jdk自带md5加密
public static void md5(String s) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(s.getBytes());
byte[] digest = md.digest();
System.out.println(Hex.encodeHexString(digest));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}