[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
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
使用AES-256CBCPKCS5填充加密解密字符串的实用程序.zip (14个子文件)
aes-256-encryption-utility-master
main-aes-keystore.jck 517B
pom.xml 6KB
src
test
resources
logback-test.xml 558B
aes-keystore.jck 517B
com
acquitygroup
encryption
KeystoreUtilTest.java 874B
java
com
acquitygroup
encryption
AESCipherTest.java 8KB
MainAppTest.java 1KB
main
resources
logback.xml 557B
java
com
acquitygroup
encryption
AESCipher.java 4KB
KeyEncoding.java 92B
KeystoreUtil.java 1KB
MainApp.java 4KB
.gitignore 188B
README.md 4KB
共 14 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9149
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功