标签:cat .sh 自带 hex org 加密 length return jar
1. 使用md5和sha256必须导入commons-codec-1.9.jar包
2. base64加密和解密是依赖于jdk自带的jar包
3. md5和sha256是不可逆的,md5加密效率较快,sha256加密安全较高
public class TestEncode {
//异或实现加密解密
public static String xor(String input){
char[] chs = input.toCharArray();
for(int i = 0; i < chs.length; i++){
chs[i] = (char) (chs[i]^3000);
}
return new String(chs);
}
//md5加密,效率较快
public static String md5Encode(byte[] input) {
return DigestUtils.md5Hex(input);
}
//sha256加密,安全较高
public static String sha256Encode(byte[] input) {
return DigestUtils.sha256Hex(input);
}
//base64加密
public static String base64Encode(byte[] input) {
String result = null;
try {
Class<?> clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
Method method = clazz.getMethod("encode", (byte[].class));
result = (String) method.invoke(null, input);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
//base64解密
public static byte[] base64Decode(String input) {
byte[] result = null;
try {
Class<?> clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
Method method = clazz.getMethod("decode", (String.class));
result = (byte[]) method.invoke(null, input);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
标签:cat .sh 自带 hex org 加密 length return jar
原文地址:https://www.cnblogs.com/pengao/p/10581332.html