Browse Source

DEC-15861 feat: Fr/Bi融合与独立部署V1

pull/1/head
zed 4 years ago
parent
commit
fb3039634b
  1. 40
      src/main/java/com/fanruan/api/security/SecurityKit.java
  2. 8
      src/test/java/com/fanruan/api/security/SecurityKitTest.java

40
src/main/java/com/fanruan/api/security/SecurityKit.java

@ -1,7 +1,9 @@
package com.fanruan.api.security; package com.fanruan.api.security;
import com.fr.security.SecurityConstant;
import com.fr.security.SecurityToolbox; import com.fr.security.SecurityToolbox;
import com.fr.stable.CodeUtils; import com.fr.stable.CodeUtils;
import com.fr.third.org.apache.commons.lang3.RandomStringUtils;
/** /**
* @author richie * @author richie
@ -12,22 +14,27 @@ import com.fr.stable.CodeUtils;
public class SecurityKit { public class SecurityKit {
/** /**
* RSA加密 * RSA加密
*
* @param plainText 要加密的文本内容 * @param plainText 要加密的文本内容
* @return 加密后的内容 * @return 加密后的内容
*/ */
public static String encrypt(String plainText) { public static String encrypt(String plainText) {
return SecurityToolbox.encrypt(plainText); return SecurityToolbox.encrypt(plainText);
} }
/** /**
* RSA解密 * RSA解密
*
* @param cipherText 密文数据 * @param cipherText 密文数据
* @return 解密后的内容 * @return 解密后的内容
*/ */
public static String decrypt(String cipherText) { public static String decrypt(String cipherText) {
return SecurityToolbox.decrypt(cipherText); return SecurityToolbox.decrypt(cipherText);
} }
/** /**
* 给字符串解密 * 给字符串解密
*
* @param passwordText 待解密的字符串 * @param passwordText 待解密的字符串
* @return 解密后的字符串 * @return 解密后的字符串
*/ */
@ -38,10 +45,43 @@ public class SecurityKit {
/** /**
* 给字符串加密 * 给字符串加密
*
* @param passwordText 待加密的字符串 * @param passwordText 待加密的字符串
* @return 解加密的字符串 * @return 解加密的字符串
*/ */
public static String passwordEncode(String passwordText) { public static String passwordEncode(String passwordText) {
return CodeUtils.passwordEncode(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);
}
} }

8
src/test/java/com/fanruan/api/security/SecurityKitTest.java

@ -1,6 +1,5 @@
package com.fanruan.api.security; package com.fanruan.api.security;
import java.util.*;
import com.fr.stable.CommonCodeUtils; import com.fr.stable.CommonCodeUtils;
import org.junit.Assert; import org.junit.Assert;
@ -11,8 +10,15 @@ public class SecurityKitTest {
public void passwordDecode() { public void passwordDecode() {
Assert.assertEquals(SecurityKit.passwordDecode("1234"), CommonCodeUtils.passwordDecode("1234")); Assert.assertEquals(SecurityKit.passwordDecode("1234"), CommonCodeUtils.passwordDecode("1234"));
} }
@Test @Test
public void passwordEncode() { public void passwordEncode() {
Assert.assertEquals(SecurityKit.passwordEncode("1234"), CommonCodeUtils.passwordEncode("1234")); 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"));
}
} }

Loading…
Cancel
Save