AdvancedEncryptionStandard
2024-08-29 00:16:59
import java.security.GeneralSecurityException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import com.citi.simpliciti.tempest.TempestRuntimeException; public class AdvancedEncryptionStandard { private static final String ALGORITHM = "AES";
private final SecretKeySpec secretKey;
private final Cipher encoder;
private final Cipher decoder; public AdvancedEncryptionStandard(byte[] key) {
try {
secretKey = new SecretKeySpec(key, ALGORITHM);
encoder = Cipher.getInstance(ALGORITHM);
encoder.init(Cipher.ENCRYPT_MODE, secretKey);
decoder = Cipher.getInstance(ALGORITHM);
decoder.init(Cipher.DECRYPT_MODE, secretKey);
} catch (Exception e) {
throw new TempestRuntimeException(e);
}
} /**
* Encrypts the given plain text
*
* @param plainText The plain text to encrypt
* @throws GeneralSecurityException
*/
public byte[] encrypt(byte[] plainText) throws GeneralSecurityException {
synchronized (encoder) {
return encoder.doFinal(plainText);
}
} /**
* Decrypts the given byte array
*
* @param cipherText The data to decrypt
* @throws GeneralSecurityException
*/
public byte[] decrypt(byte[] cipherText) throws GeneralSecurityException {
synchronized (decoder) {
return decoder.doFinal(cipherText);
}
}
}
最新文章
- day04关于MySqL—Android小白的学习笔记
- background常用属性
- pandas入门
- android: 活动和服务进行通信
- html 隐藏滚动条
- HTML基础-- 标签、表格
- C++ Language
- 1.4.8 拼凑在一起(putting the pieces together)
- Centos 安装KScope1.6.2
- Java 解析epub格式电子书,helloWorld程序,附带源程序和相关jar包
- SQL语句之三简单增删改查
- CentOS 6.3下Samba服务器的安装与配置(转)
- ie调试控制台
- Visual Studio 2013 Preview - ASP.NET, MVC 5, Web API 2新功能搶先看
- angular localStorage使用方法
- 初识Eclipse!!
- Quick Introduction to SQL Server Profiler
- scrapy 框架入门
- Keil5 如何安装STM32 芯片包
- Kafka 0.10问题点滴