Commit b9c8f912 by 李传峰

加入AES加密工具类,增加long的常用方法

parent fefa336f
......@@ -24,6 +24,24 @@ public class AESUtil {
* @param src 待加密数据
* @return 加密后数据
*/
public static String fixedLongEncrypt(final long src) {
return fixedEncrypt(String.valueOf(src));
}
/**
* 使用固定密钥解密
* @param encrypted 待解密数据
* @return 解密后结果
*/
public static long fixedLongDecrypt(final String encrypted) {
return Long.parseLong(fixedDecrypt(encrypted));
}
/**
* 使用固定密钥加密
* @param src 待加密数据
* @return 加密后数据
*/
public static String fixedEncrypt(final String src) {
if (StringUtils.isBlank(src)) {
return src;
......
......@@ -13,6 +13,8 @@ public class AESUtilTest {
exec("123456");
exec("123456efg");
exec("我是中国人");
exec(9632587L);
exec(Long.MAX_VALUE);
}
private void exec(String src) {
......@@ -20,4 +22,10 @@ public class AESUtilTest {
String d = AESUtil.fixedDecrypt(e);
Assert.assertEquals(d, src);
}
private void exec(long src) {
String e = AESUtil.fixedLongEncrypt(src);
long d = AESUtil.fixedLongDecrypt(e);
Assert.assertEquals(d, src);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment