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. Consumer设计-high/low Level Consumer

    1 Producer和Consumer的数据推送拉取方式   Producer Producer通过主动Push的方式将消息发布到Broker n Consumer Consumer通过Pull从Br ...

  2. day17 12.复习

    最后能抽取成word文档或者是图片之类的. 1.jdbc介绍  jdbc是一套标准,可以让我们Java程序员通过Java代码直接操作数据库,这就够了.jdbc涉及到的包两个:java.sql,java ...

  3. STM32 C++编程 004 Adc (数模转换)类

    使用 C++ 语言给 STM32 编写一个 Adc 类 我使用的STM32芯片:STM32F103ZET6 我们使用的STM32库版本:V3.5.0 注意: 想学习本套 STM32 C++编程 的专栏 ...

  4. ARC059F

    传送门 分析 见ptx大爷博客 代码 #include<iostream> #include<cstdio> #include<cstring> #include& ...

  5. hihocoder1513 小Hi的烦恼

    传送门 分析 论bitset的妙用......我们利用桶排将输入的数据排序,之后分别考虑5维,a[i][j]表示考虑第i个人第j维的情况下于其它人的大小关系.最后将5维的信息并起来求1的个数即可 代码 ...

  6. Entity Framework Tutorial Basics(14):Choose development approach

    Choose development approach with Entity Framework: We have seen Code-first, Model-first and Database ...

  7. Android 实现形态各异的双向侧滑菜单 自定义控件来袭(转载)

    1.概述 关于自定义控件侧滑已经写了两篇了~~今天决定把之前的单向改成双向,当然了,单纯的改动之前的代码也没意思,今天不仅会把之前的单向改为双向,还会多添加一种侧滑效果,给大家带来若干种形态各异的双向 ...

  8. C++面试笔记--单链表

    1.编程实现单链表删除节点.       解析:如果删除的是头节点,如下图: 则把head指针指向头节点的下一个节点.同时free p1,如下图所示: 如果删除的是中间节点,如下图所示: 则用p2的n ...

  9. 【LeetCode】将罗马数字转换成10进制数

    Roman to Integer Given a roman numeral, convert it to an integer. 首先介绍罗马数字 罗马数字共有七个,即I(1),V(5),X(10) ...

  10. 解决Visiual Studio2012 CLR20r3问题

    解决办法: 步骤1:开始-->所有程序-->Microsoft Visual Studio 2012-->Visual Studio Tools-->VS2012 开发人员命令 ...