From a088987e7ab7005db1bb1da61dfc0cf420e02d78 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 17:11:28 +0800 Subject: [PATCH] 1 --- src/main/java/com/moon/server/helper/AesHelper.java | 71 ----------------------------------- 1 files changed, 1 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/moon/server/helper/AesHelper.java b/src/main/java/com/moon/server/helper/AesHelper.java index 4610cd3..f606f3c 100644 --- a/src/main/java/com/moon/server/helper/AesHelper.java +++ b/src/main/java/com/moon/server/helper/AesHelper.java @@ -4,75 +4,30 @@ import javax.crypto.spec.SecretKeySpec; import java.util.Base64; -/** - * AES鍔犲瘑甯姪 - * @author WWW - */ -@SuppressWarnings("restriction") +@SuppressWarnings("ALL") public class AesHelper { - /** - * 瀵嗛挜闀垮害蹇呴』鏄�16 - */ private static final String DEFAULT_KEY = "A#s_lF_sErve_k.y"; private static final String KEY_ALGORITHM = "AES"; - /** - * 绠楁硶 - */ private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding"; - /** - * aes瑙e瘑 - * - * @param encrypt 鍐呭 - * @return - * @throws Exception - */ public static String decrypt(String encrypt) throws Exception { return decrypt(encrypt, DEFAULT_KEY); } - /** - * aes鍔犲瘑 - * - * @param content 鍐呭 - * @return - * @throws Exception - */ public static String encrypt(String content) throws Exception { return encrypt(content, DEFAULT_KEY); } - /** - * base 64 encode - * - * @param bytes 寰呯紪鐮佺殑byte[] - * @return 缂栫爜鍚庣殑base64 code - */ private static String base64Encode(byte[] bytes) { return Base64.getEncoder().encodeToString(bytes); } - /** - * base 64 decode - * - * @param base64Code 寰呰В鐮佺殑base64 code - * @return 瑙g爜鍚庣殑byte[] - * @throws Exception - */ private static byte[] base64Decode(String base64Code) { return StringHelper.isEmpty(base64Code) ? null : Base64.getDecoder().decode(base64Code); } - /** - * AES鍔犲瘑 - * - * @param content 寰呭姞瀵嗙殑鍐呭 - * @param encryptKey 鍔犲瘑瀵嗛挜 - * @return 鍔犲瘑鍚庣殑byte[] - * @throws Exception - */ private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM) // kGen.init(128) @@ -83,38 +38,14 @@ return cipher.doFinal(content.getBytes("utf-8")); } - /** - * AES鍔犲瘑涓篵ase 64 code - * - * @param content 寰呭姞瀵嗙殑鍐呭 - * @param encryptKey 鍔犲瘑瀵嗛挜 - * @return 鍔犲瘑鍚庣殑base 64 code - * @throws Exception - */ public static String encrypt(String content, String encryptKey) throws Exception { return base64Encode(aesEncryptToBytes(content, encryptKey)); } - /** - * 灏哹ase 64 code AES瑙e瘑 - * - * @param encryptStr 寰呰В瀵嗙殑base 64 code - * @param decryptKey 瑙e瘑瀵嗛挜 - * @return 瑙e瘑鍚庣殑string - * @throws Exception - */ public static String decrypt(String encryptStr, String decryptKey) throws Exception { return StringHelper.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); } - /** - * AES瑙e瘑 - * - * @param encryptBytes 寰呰В瀵嗙殑byte[] - * @param decryptKey 瑙e瘑瀵嗛挜 - * @return 瑙e瘑鍚庣殑String - * @throws Exception - */ private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM) // kGen.init(128) -- Gitblit v1.9.3