From a666b5f9741ef9b21f547d3b2141752a0383c70c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 20 九月 2022 17:07:38 +0800 Subject: [PATCH] 1、修改登录页面 2、修改阿里代码规范问题 --- src/java/org/apereo/cas/web/landtool/utils/AbstractCoderUtils.java | 87 +++++++++++++++++++++---------------------- 1 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/java/org/apereo/cas/web/landtool/utils/CoderUtils.java b/src/java/org/apereo/cas/web/landtool/utils/AbstractCoderUtils.java similarity index 60% rename from src/java/org/apereo/cas/web/landtool/utils/CoderUtils.java rename to src/java/org/apereo/cas/web/landtool/utils/AbstractCoderUtils.java index d13895f..3cf8192 100644 --- a/src/java/org/apereo/cas/web/landtool/utils/CoderUtils.java +++ b/src/java/org/apereo/cas/web/landtool/utils/AbstractCoderUtils.java @@ -9,15 +9,11 @@ import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; - -//import sun.misc.BASE64Decoder; -//import sun.misc.BASE64Encoder; - /** * 鍩虹鍔犲瘑缁勪欢 * @author TanBin */ -public abstract class CoderUtils { +public abstract class AbstractCoderUtils { public static final String KEY_SHA = "SHA"; public static final String KEY_MD5 = "MD5"; @@ -37,36 +33,39 @@ * BASE64鍔犲瘑 * @param key * @return - * @throws Exception + * @throws Exception + * + * 娉�1锛氫娇鐢╯un.misc濂椾欢銆�1.6涔嬪墠锛� 鏁堢巼涓嶅ソ锛屾柊JDK涓嶆敮鎸� + * return (new BASE64Encoder()).encodeBuffer(data); + * + * 娉�2锛氫娇鐢ˋpache Commons Codec銆� + * return (new Base64()).encodeToString(data); + * + * 娉�3锛氫娇鐢↗ava 8鐨刯ava.util濂椾欢銆� 鏁堢巼鏄�1鐨�11鍊嶏紝鏄�2鐨�3鍊嶄互涓娿�� */ - public static String encryptBASE64(byte[] data) { - //text.getBytes("UTF-8"); new String(decoder.decode(encodedText), "UTF-8") - //娉�1锛氫娇鐢╯un.misc濂椾欢銆�1.6涔嬪墠锛� 鏁堢巼涓嶅ソ锛屾柊JDK涓嶆敮鎸� -// return (new BASE64Encoder()).encodeBuffer(data); - - //娉�2锛氫娇鐢ˋpache Commons Codec銆� -// return (new Base64()).encodeToString(data); - - //娉�3锛氫娇鐢↗ava 8鐨刯ava.util濂椾欢銆� 鏁堢巼鏄�1鐨�11鍊嶏紝鏄�2鐨�3鍊嶄互涓娿�� + public static String encryptBase64(byte[] data) { + //text.getBytes("UTF-8"); new String(decoder.decode(encodedText), "UTF-8") + return Base64.getEncoder().encodeToString(data); - } + } /** * BASE64瑙e瘑 * @param key * @return - * @throws Exception + * @throws Exception + * + * 娉�1锛氫娇鐢╯un.misc濂椾欢銆� 鏁堢巼涓嶅ソ锛屾柊JDK涓嶆敮鎸� + * return (new BASE64Decoder()).decodeBuffer(key); + * + * 娉�2锛氫娇鐢ˋpache Commons Codec銆� + * return (new Base64()).decode(key); + * + * 娉�3锛氫娇鐢↗ava 8鐨刯ava.util濂椾欢銆� 鏁堢巼鏄�1鐨�11鍊嶏紝鏄�2鐨�3鍊嶄互涓娿�� */ - public static byte[] decryptBASE64(String key) { - //娉�1锛氫娇鐢╯un.misc濂椾欢銆� 鏁堢巼涓嶅ソ锛屾柊JDK涓嶆敮鎸� -// return (new BASE64Decoder()).decodeBuffer(key); - - //娉�2锛氫娇鐢ˋpache Commons Codec銆� -// return (new Base64()).decode(key); - - //娉�3锛氫娇鐢↗ava 8鐨刯ava.util濂椾欢銆� 鏁堢巼鏄�1鐨�11鍊嶏紝鏄�2鐨�3鍊嶄互涓娿�� - return Base64.getDecoder().decode(key); - } + public static byte[] decryptBase64(String key) { + return Base64.getDecoder().decode(key); + } /** * MD5鍔犲瘑 @@ -74,7 +73,7 @@ * @return * @throws Exception */ - public static byte[] encryptMD5(byte[] data) throws Exception{ + public static byte[] encryptMd5(byte[] data) throws Exception{ MessageDigest md5 = MessageDigest.getInstance(KEY_MD5); md5.update(data); return md5.digest(); @@ -86,8 +85,8 @@ * @return * @throws Exception */ - public static String lantuEncryptMD5(String text) throws Exception{ - byte[] b = encryptMD5(text.getBytes("UTF-8")); + public static String lantuEncryptMd5(String text) throws Exception{ + byte[] b = encryptMd5(text.getBytes("UTF-8")); String key = convertToHexString(b); //杞负澶у啓 key = key.toUpperCase(); @@ -105,7 +104,7 @@ * @param data * @return */ - private static String convertToHexString(byte data[]) { + private static String convertToHexString(byte[] data) { StringBuffer strBuffer = new StringBuffer(); for (int i = 0; i < data.length; i++) { //strBuffer.append(Integer.toHexString(0xff & data[i])); //30bit @@ -124,7 +123,7 @@ * @return * @throws Exception */ - public static byte[] encryptSHA(byte[] data) throws Exception{ + public static byte[] encryptSha(byte[] data) throws Exception{ MessageDigest sha = MessageDigest.getInstance(KEY_SHA); sha.update(data); return sha.digest(); @@ -138,7 +137,7 @@ public static String initMacKey() throws Exception{ KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_MAC); SecretKey secretKey = keyGenerator.generateKey(); - return encryptBASE64(secretKey.getEncoded()); + return encryptBase64(secretKey.getEncoded()); } /** @@ -148,8 +147,8 @@ * @return * @throws Exception */ - public static byte[] encryptHMAC(byte[] data, String key) throws Exception{ - SecretKey secretKey = new SecretKeySpec(decryptBASE64(key), KEY_MAC); + public static byte[] encryptHmac(byte[] data, String key) throws Exception{ + SecretKey secretKey = new SecretKeySpec(decryptBase64(key), KEY_MAC); Mac mac = Mac.getInstance(secretKey.getAlgorithm()); mac.init(secretKey); return mac.doFinal(data); @@ -159,19 +158,19 @@ String inputStr = "123456"; System.err.println("鍘熸枃:" + inputStr); try { - String codeBASE64 = encryptBASE64(inputStr.getBytes("UTF-8")); - String codeMD5 = lantuEncryptMD5(inputStr); - byte[] codeSHA = encryptSHA(inputStr.getBytes("UTF-8")); + String codeBase64 = encryptBase64(inputStr.getBytes("UTF-8")); + String codeMd5 = lantuEncryptMd5(inputStr); + byte[] codeSha = encryptSha(inputStr.getBytes("UTF-8")); String key = initMacKey(); System.err.println("Mac瀵嗛挜:" + key); - byte[] codeHMAC = encryptHMAC(inputStr.getBytes("UTF-8"), key); + byte[] codeHmac = encryptHmac(inputStr.getBytes("UTF-8"), key); - System.err.println("\nBASE64:" + codeBASE64); - System.err.println("BASE64瑙e瘑:" + new String(decryptBASE64(codeBASE64),"UTF-8")); - System.err.println("MD5:" + codeMD5); - System.err.println("SHA:" + codeSHA); - System.err.println("HMAC:" + codeHMAC); + System.err.println("\nBASE64:" + codeBase64); + System.err.println("BASE64瑙e瘑:" + new String(decryptBase64(codeBase64),"UTF-8")); + System.err.println("MD5:" + codeMd5); + System.err.println("SHA:" + codeSha); + System.err.println("HMAC:" + codeHmac); } catch (Exception e) { // TODO Auto-generated catch block -- Gitblit v1.9.3