From fb3039634b6e304a377c396a5210193d7d3fb98f Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 18 Dec 2020 09:27:39 +0800 Subject: [PATCH] =?UTF-8?q?DEC-15861=20feat:=20Fr/Bi=E8=9E=8D=E5=90=88?= =?UTF-8?q?=E4=B8=8E=E7=8B=AC=E7=AB=8B=E9=83=A8=E7=BD=B2V1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fanruan/api/security/SecurityKit.java | 40 +++++++++++++++++++ .../fanruan/api/security/SecurityKitTest.java | 12 ++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fanruan/api/security/SecurityKit.java b/src/main/java/com/fanruan/api/security/SecurityKit.java index 59c90d8..dd02709 100644 --- a/src/main/java/com/fanruan/api/security/SecurityKit.java +++ b/src/main/java/com/fanruan/api/security/SecurityKit.java @@ -1,7 +1,9 @@ package com.fanruan.api.security; +import com.fr.security.SecurityConstant; import com.fr.security.SecurityToolbox; import com.fr.stable.CodeUtils; +import com.fr.third.org.apache.commons.lang3.RandomStringUtils; /** * @author richie @@ -12,22 +14,27 @@ import com.fr.stable.CodeUtils; public class SecurityKit { /** * RSA加密 + * * @param plainText 要加密的文本内容 * @return 加密后的内容 */ public static String encrypt(String plainText) { return SecurityToolbox.encrypt(plainText); } + /** * RSA解密 + * * @param cipherText 密文数据 * @return 解密后的内容 */ public static String decrypt(String cipherText) { return SecurityToolbox.decrypt(cipherText); } + /** * 给字符串解密 + * * @param passwordText 待解密的字符串 * @return 解密后的字符串 */ @@ -38,10 +45,43 @@ public class SecurityKit { /** * 给字符串加密 + * * @param passwordText 待加密的字符串 * @return 解加密的字符串 */ public static String passwordEncode(String passwordText) { return CodeUtils.passwordEncode(passwordText); } + + /** + * aes加密 + * + * @param plainText 明文 + * @param seed seed + * @return 密文 + */ + public static String aesEncrypt(String plainText, String seed) { + return SecurityToolbox.aesEncrypt(plainText, seed); + } + + /** + * aes解密 + * + * @param cipherText 密文 + * @param seed seed + * @return 明文 + */ + public static String aesDecrypt(String cipherText, String seed) { + return SecurityToolbox.aesDecrypt(cipherText, seed); + } + + /** + * 生成seed + * + * @return seed + */ + public static String createSeed() { + return RandomStringUtils.randomAlphabetic(SecurityConstant.SEED_LENGTH); + } + } diff --git a/src/test/java/com/fanruan/api/security/SecurityKitTest.java b/src/test/java/com/fanruan/api/security/SecurityKitTest.java index 6760606..a8a2bd0 100644 --- a/src/test/java/com/fanruan/api/security/SecurityKitTest.java +++ b/src/test/java/com/fanruan/api/security/SecurityKitTest.java @@ -1,6 +1,5 @@ package com.fanruan.api.security; -import java.util.*; import com.fr.stable.CommonCodeUtils; import org.junit.Assert; @@ -8,11 +7,18 @@ import org.junit.Test; public class SecurityKitTest { @Test - public void passwordDecode(){ + public void passwordDecode() { Assert.assertEquals(SecurityKit.passwordDecode("1234"), CommonCodeUtils.passwordDecode("1234")); } + @Test - public void passwordEncode(){ + public void passwordEncode() { Assert.assertEquals(SecurityKit.passwordEncode("1234"), CommonCodeUtils.passwordEncode("1234")); } + + @Test + public void aes() { + String text = SecurityKit.aesEncrypt("zed", "IrgwAINYUSLqVxHL"); + Assert.assertEquals("zed", SecurityKit.aesDecrypt(text, "IrgwAINYUSLqVxHL")); + } }