Base64編碼是從二進制到字符的過程,可用於在HTTP環境下傳遞較長的標識信息。
Base64是個字符串
pom.xml配置
<dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.10</version> </dependency>
加密解密代碼
/** * 解密 * * @param pwd * @return * @see [類、類#方法、類#成員] */ public static String decodeStr(String pwd) { Base64 base64 = new Base64(); byte[] debytes = base64.decodeBase64(new String(pwd).getBytes()); return new String(debytes); } /** * 加密 * * @param pwd * @return * @see [類、類#方法、類#成員] */ public static String encodeStr(String pwd) { Base64 base64 = new Base64(); byte[] enbytes = base64.encodeBase64Chunked(pwd.getBytes()); return new String(enbytes); }
大家覺得不錯的話可以支持一下

