Browse Source

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

Merge in TC/finekit from ~ZED/finekit:master to master

* commit '420bc83904e95c31570d4d8648d0de0423c3ef60':
  DEC-15861 feat: Fr/Bi融合与独立部署V1
  DEC-15861 feat: Fr/Bi融合与独立部署V1
master
zed 4 years ago
parent
commit
defd3cce2a
  1. 40
      src/main/java/com/fanruan/api/security/SecurityKit.java
  2. 11
      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);
}
}

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

@ -1,18 +1,25 @@
package com.fanruan.api.security;
import java.util.*;
import com.fr.stable.CommonCodeUtils;
import org.junit.Assert;
import org.junit.Test;
public class SecurityKitTest {
@Test
public void passwordDecode() {
Assert.assertEquals(SecurityKit.passwordDecode("1234"), CommonCodeUtils.passwordDecode("1234"));
}
@Test
public void passwordEncode() {
Assert.assertEquals(SecurityKit.passwordEncode("1234"), CommonCodeUtils.passwordEncode("1234"));
}
@Test
public void aes() {
String seed = SecurityKit.createSeed();
String text = SecurityKit.aesEncrypt("zed", seed);
Assert.assertEquals("zed", SecurityKit.aesDecrypt(text, seed));
}
}

Loading…
Cancel
Save