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的更多相关文章

  1. 【C#公共帮助类】给大家分享一些加密算法 (DES、HashCode、RSA、AES等)

    AES 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的 ...

  2. 解决IllegalBlockSizeException:last block incomplete in decryption异常

    解决IllegalBlockSizeException:last block incomplete in decryption异常分类: webkit android最近做个加解密的实现,虽然实现了, ...

  3. Delphi与JAVA互加解密AES算法

    搞了半天终于把这个对应的参数搞上了,话不多说,先干上代码: package com.bss.util; import java.io.UnsupportedEncodingException; imp ...

随机推荐

  1. js中的各种宽高

    在设计页面时可能经常会用到固定层的位置,这就需要获取一些html对象的坐标以更灵活的设置目标层的坐标,这里可能就会用到document .body.scrollTop等属性,但是此属性在xhtml标准 ...

  2. Contset Hunter 1102 高精度求卡特兰数

    用递推的方式写的写挂了,而如果用组合数又不会高精度除法,偶然看到了别人的只用高精度乘低精度求组合数的方法,记录一下 #include<bits/stdc++.h> using namesp ...

  3. 吸收效果,像是在Mac上的垃圾桶的效果一样

    #import "AppDelegate.h" #import <QuartzCore/QuartzCore.h> @interface AppDelegate () ...

  4. ZROI2018提高day4t1

    传送门 分析 一道贪心题,我们用两个优先队列分别维护卖出的物品的价格和买入但没有卖出的物品的价格,然后逐一考虑每一个物品.对于每一个物品如果他比卖出的物品中的最低个价格,则改将现在考虑的物品卖出,将之 ...

  5. Luogu 1979 [NOIP2013] 华容道

    要优先安排历年NOIP题 考虑到要移动,肯定要先把空的格子移动到起点旁边,所以我们对于每一个询问都先bfs一次求出把空格移到起点的四个位置的最短路,而且要保证不能移动起点的方块. 只有空的格子在一个格 ...

  6. WOJ 43 电话邀请

    并查集缩点这个trick感觉明明用得很广泛,为什么以前都不知道…… 先把$m$条线路从小到大排个序,这样可以保证之前合并出来的一定是最小的,大的代价不会把小的覆盖掉. 维护两个并查集,一个用来缩点,另 ...

  7. rest-framework组件 之 解析器

    解析器 request类 django的request类和rest-framework的request类的源码解析 局部视图 from rest_framework.parsers import JS ...

  8. C# 实现文件(夹)在ftp服务器间的同步【无需将文件(夹)保存到本地】

    C#实现不同ftp服务器间文件(夹)同步 图1 实现不同ftp服务器间文件(夹)同步的实现思路图 /// <summary> /// 将文件夹1从ftp服务器1移到ftp服务器2文件夹2 ...

  9. Html.DropDownListFor 练习

    需要创建一个List<SelectListItem>数据集,如下 使用已经存在FruitCategoryEntity.cs类的IEnumerable<FruitCategory> ...

  10. jquery easyui datagrid 多选只能获取一条数据

    DataGrid属性: singleSelect ------如果为true,则只允许选择一行: idField ------- 指明哪一个字段是标识字段: 方法: 一:getSelections-- ...