|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|