Java开发
总结java开发中知识点和问题点
基础:
常用加解密算法:
[md5]
import java.security.MessageDigest;
public static final String encodeMD5(String str) { final byte m = 15; char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; try { byte[] bytes = str.getBytes(); MessageDigest instance = MessageDigest.getInstance("MD5"); instance.update(bytes); byte[] digest = instance.digest(); int length = digest.length; char[] cArr2 = new char[(length * 2)]; int i = 0; for (byte b : digest) { int i2 = i + 1; cArr2[i] = cArr[(b >>> 4) & 15]; i = i2 + 1; cArr2[i2] = cArr[b & m]; } return new String(cArr2).toLowerCase(); } catch (Exception e) { e.printStackTrace(); return null; } }
[base64]
import java.util.Base64; public static void base64() { String name = "xing"; Base64.Encoder encoder = Base64.getEncoder(); String base64Str = encoder.encodeToString(name.getBytes()); System.out.println("base64Str:"+base64Str); // 解码 Base64.Decoder decoder = Base64.getDecoder(); byte[] res = decoder.decode(base64Str); String srcStr = new String(res); System.out.println("res:"+srcStr); }
[encode/decode]