[Run](#run) | [How To Use](#howto) | [Generate AES-256 Key](#generate) | [View AES-256 Key](#view) | [Command Line Encrypt/Decrypt](#use)
Overview:
===================
This is a sample utility to encrypt/decrypt using AES/CBC/PKCS5Padding algorithm
_Most common error_: "Invalid Key Size" error is most likely caused by not updating JCE strength policy, see above
**NOTE:** This example is built using **JDK7**, ultimate strength JCE (JDK7) and [Maven 3.x](http://maven.apache.org "Maven Documentation")
- [Unlimited Strength Policy JDK7](http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html "Unlimited Strength Policy for JDK7")
- JDK must have the unlimited strength policy for the JDK version
<a name="run"></a>To Run:
====================
mvn clean test
[Run](#run) | [How To Use](#howto) | [Generate AES-256 Key](#generate) | [View AES-256 Key](#view) | [Command Line Encrypt/Decrypt](#use)
<a name="howto"></a>To Use:
====================
# Key stored in JCEKS formatted Java keystore
Key key = ....; // see tests pulling key from keystore
// alternative is to hard-code key in string
AESCipher cipher = new AESCipher(key);
String encryptedMessage = cipher.getEncryptedMessage("this is message");
String decryptedMessage = cipher.getDecryptedMessage(encryptedMessage);
AESCipher cipherWithIv = new AESCipher(key, "0123456789012345".getBytes());
String encryptedMessage = cipherWithIv.getEncryptedMessage("this is message");
String decryptedMessage = cipherWithIv.getDecryptedMessage(encryptedMessage);
[Run](#run) | [How To Use](#howto) | [Generate AES-256 Key](#generate) | [View AES-256 Key](#view) | [Command Line Encrypt/Decrypt](#use)
<a name="generate"></a>Generate an AES-256 Key
======================
keytool -genseckey -alias jceksaes -keyalg AES -keysize 256 -storetype JCEKS -keypass mykeypass -storetype jceks -keystore aes-keystore.jck -storepass mystorepass
[Run](#run) | [How To Use](#howto) | [Generate AES-256 Key](#generate) | [View AES-256 Key](#view) | [Command Line Encrypt/Decrypt](#use)
<a name="view"></a>View AES-256 Key from command line
======================
mvn clean package // generate executable JAR file
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar <COMMAND like 'showKey'>
// or optionally with Maven (using the above defaults)
mvn exec:java
[Run](#run) | [How To Use](#howto) | [Generate AES-256 Key](#generate) | [View AES-256 Key](#view) | [Command Line Encrypt/Decrypt](#use)
<a name="use"></a>Encrypt/Decrypt AES-256 from command line
======================
// Generate executable JAR with: mvn package
// Ideally the IV passed in (0000000000000000) would be randomly generated
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar encrypt blahblahblah 0000000000000000
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar decrypt baN3CIAcVgq+AQr7lvKmLw== 0000000000000000
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar encrypt blahblahblah 0000000000000001
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar decrypt Wcaov8LNN4GJvp1bvOTJ0g== 0000000000000001
[Run](#run) | [How To Use](#howto) | [Generate AES-256 Key](#generate) | [View AES-256 Key](#view) | [Command Line Encrypt/Decrypt](#use)
Copywrite ©2013 - Use of this code and it's concepts are considered a Proof-of-concept and should not be used directly in any environment
快撑死的鱼
- 粉丝: 2w+
- 资源: 9156
最新资源
- 数据库大作业01234.zip
- 飞机故障诊断技术学期考查作业模板:编写规范及内容指引
- 纯电动汽车两档ATM变速箱simulink模型,模型实现了两档AMT挡策略和挡过程仿真,内含详细文档和注释模型,可运行
- 基于LM393比较器与LM321运放电流采样及硬件过流检测电路
- 4-IEEE trans顶刊复现,水下机器人AUV的路径规划和基于模型预测控制MPC的跟踪框架 参考文献和建模过程请参考图片中的文章,本代码包括路径规划和MPC路径跟踪两个模块,两个模块均采用优化求
- 数据挖掘管道搭建示例 基于大航杯“智造扬中”电力AI大赛.zip
- MATLAB直线倒立摆一阶倒立摆LQR控制仿真,小车倒立摆起摆和平衡控制,附带参考文献 三种控制方法对比 pd控制、lqr控制、mpc模型预测控制
- anaconda配置pytorch环境.md
- 数据结构与算法基础(青岛大学-王卓).zip
- 无穷大功率电源供电系统三相短路Matlab Simulink仿真 1.仿真在0.02s变压器低压母线发生三相短路故障,仿真其短路电流周期分量幅值和冲击电流的大小 2.仿真的具体参数见下图,按照仿真数据
- COMSOL 光学 手性 BIC 仿真 光子晶体板中连续域束缚态 BIC 赋予的手性 包含正入射斜入射琼斯矩阵透射谱,模式耦合各种透射谱分量,动量空间偏振图 下图是仿真文件截图,所见即所得
- 日常总结java + 大数据.zip
- 暨南大学计算机系数据库课程设计.zip
- 本系统是我的毕业设计项目,题目为“基于用户画像的电影推荐系统的设计与实现” 主要是以Django作为基础框架,采用MTV模式,数据库使用MongoDB、MySQL和Redis,以从豆瓣平台爬取.zip
- 本项目使用C++实现基于跳表实现的轻量级键值型存储引擎,其主要功能有插入数据、查询数据、删除数据、数据展示、数据库大小、数据库清空、数据落盘以及文件加载数据 .zip
- 条形码的那些事儿:为什么 12345242 变成了 12345243?
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈