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

最新文章

  1. day04关于MySqL—Android小白的学习笔记
  2. background常用属性
  3. pandas入门
  4. android: 活动和服务进行通信
  5. html 隐藏滚动条
  6. HTML基础-- 标签、表格
  7. C++ Language
  8. 1.4.8 拼凑在一起(putting the pieces together)
  9. Centos 安装KScope1.6.2
  10. Java 解析epub格式电子书,helloWorld程序,附带源程序和相关jar包
  11. SQL语句之三简单增删改查
  12. CentOS 6.3下Samba服务器的安装与配置(转)
  13. ie调试控制台
  14. Visual Studio 2013 Preview - ASP.NET, MVC 5, Web API 2新功能搶先看
  15. angular localStorage使用方法
  16. 初识Eclipse!!
  17. Quick Introduction to SQL Server Profiler
  18. scrapy 框架入门
  19. Keil5 如何安装STM32 芯片包
  20. Kafka 0.10问题点滴

热门文章

  1. ElasticSearch入门一
  2. C++ 面向对象: I/O对象的应用
  3. Damn Couples ZOJ - 3161
  4. CF1063B Labyrinth
  5. CF 1029E Tree with Small Distances
  6. 有趣的setTimeout
  7. 数据结构 merge_link合并链表
  8. 操作系统--UNIX代码段和数据段分开
  9. enum枚举型
  10. maredit测试