AdvancedEncryptionStandard
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);
}
}
}
AdvancedEncryptionStandard的更多相关文章
- 【C#公共帮助类】给大家分享一些加密算法 (DES、HashCode、RSA、AES等)
AES 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的 ...
- 解决IllegalBlockSizeException:last block incomplete in decryption异常
解决IllegalBlockSizeException:last block incomplete in decryption异常分类: webkit android最近做个加解密的实现,虽然实现了, ...
- Delphi与JAVA互加解密AES算法
搞了半天终于把这个对应的参数搞上了,话不多说,先干上代码: package com.bss.util; import java.io.UnsupportedEncodingException; imp ...
随机推荐
- 图片缓存核心类LruCache
该类类似一个缓存池,具体可参考 http://www.fengfly.com/plus/view-214546-2.html
- HDU 6396(2018多校第七场1011) Swordsman
场上场下各种TLE到怀疑人生...经过大佬指点之后才知道要用fread才能过,一般的快读不行... 题意:一个剑客打小怪兽,有n头小怪兽,剑客和小怪兽有m个属性.只有剑客的m个属性都大于等于某个小怪兽 ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-007归并排序(自下而上)
一. 1. 2. 3. 二.代码 package algorithms.mergesort22; import algorithms.util.StdIn; import algorithms.uti ...
- Luogu 1979 [NOIP2013] 华容道
要优先安排历年NOIP题 考虑到要移动,肯定要先把空的格子移动到起点旁边,所以我们对于每一个询问都先bfs一次求出把空格移到起点的四个位置的最短路,而且要保证不能移动起点的方块. 只有空的格子在一个格 ...
- Entity Framework Tutorial Basics(17):DBSet Class
DBSet Class DBSet class represents an entity set that is used for create, read, update, and delete o ...
- Google B4网络阅读记录(翻译)
3.设计 这一章我们描述软件定义广域网架构的细节. 3.1.概述 我们的软件定义网络从逻辑上可以看做三层,如图所示, B4服务于多个广域网节点,每个节点都有很多服务器集群.在每个B4节点内,交换机硬件 ...
- String、StringBuffer与StringBuilder之间区别 .RP
最近学习到StringBuffer,心中有好些疑问,搜索了一些关于String,StringBuffer,StringBuilder的东西,现在整理一下. 关于这三个类在字符串处理中的位置不言而喻,那 ...
- eclipse中jad反编译工具的安装
我的云盘:工具里面有 Q:为什么有必要在开发环境中配置反编译工具呢? A: 当运行引用了第三方jar包项目时,突然报出了jar包中的某个类的某一行出现异常.我们想看一下这个class文件的代码时,经 ...
- android自定义视图属性(atts.xml,TypedArray)学习
是一个用于存放恢复obtainStyledAttributes(AttributeSet, int[], int, int)或 obtainAttributes(AttributeSet, int[] ...
- CodeForces 658C Bear and Forgotten Tree 3 (构造)
题意:构造出一个 n 个结点,直径为 m,高度为 h 的树. 析:先构造高度,然后再构造直径,都全了,多余的边放到叶子上,注意直径为1的情况. 代码如下: #pragma comment(linker ...