Browse Source

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

remotes/1611766341912730171/master
zed 4 years ago
parent
commit
fb3039634b
  1. 40
      src/main/java/com/fanruan/api/security/SecurityKit.java
  2. 12
      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;
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);
}
}

12
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"));
}
}

Loading…
Cancel
Save