1 Star 0 Fork 0

Vincent_Field/EY_Code_Leak_Test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
AES.java 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
Vincent_Field 提交于 2019-12-16 15:14 . update AES.java.
package com.cs.coder.util;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* @author Vince
* @date 2019/12/10 14:24
*/
public class AES {
private static final String AES_MODE = "AES/ECB/PKCS5Padding";
// private static final int keySize = 16;
// test search key gitwanlishi
// wwww
public static byte[] decrypt(byte[] key, byte[] data, int keySize) {
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(trimKeySize(key, keySize), "AES");
Cipher instance = Cipher.getInstance(AES_MODE);
instance.init(2, secretKeySpec);
return instance.doFinal(data);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace();
return null;
}
}
@SuppressWarnings("SameParameterValue")
private static byte[] trimKeySize(byte[] key, int keySize) {
byte[] bArr2 = new byte[keySize];
if (key.length <= keySize) {
keySize = key.length;
}
System.arraycopy(key, 0, bArr2, 0, keySize);
return bArr2;
}
public static byte[] encrypt(byte[] key, byte[] data, int keySize) {
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(trimKeySize(key, keySize), "AES");
Cipher instance = Cipher.getInstance(AES_MODE);
instance.init(1, secretKeySpec);
return instance.doFinal(data);
} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException e) {
e.printStackTrace();
return null;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/VincentField/EY_Code_Leak_Test.git
git@gitee.com:VincentField/EY_Code_Leak_Test.git
VincentField
EY_Code_Leak_Test
EY_Code_Leak_Test
master

搜索帮助