AES加密解密
2016-08-25 16:11
316 查看
# AES加密解密 import javax.crypto.*; import java.security.*; public class Java { private static SecretKey key = null; private static Cipher cipher = null; public static void main(String[] args) throws Exception { Security.addProvider(new com.sun.crypto.provider.SunJCE()); KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede"); keyGenerator.init(168); SecretKey secretKey = keyGenerator.generateKey(); cipher = Cipher.getInstance("DESede"); String clearText = "I am an Employee"; byte[] clearTextBytes = clearText.getBytes("UTF8"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] cipherBytes = cipher.doFinal(clearTextBytes); String cipherText = new String(cipherBytes, "UTF8"); cipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] decryptedBytes = cipher.doFinal(cipherBytes); String decryptedText = new String(decryptedBytes, "UTF8"); System.out.println("Before encryption: " + clearText); System.out.println("After encryption: " + cipherText); System.out.println("After decryption: " + decryptedText); } }
相关文章推荐
- .NET分页控件简单学习
- JAVA彩色终端库javacurses的使用 -- 感觉并不好
- startActivityForResult用法
- 简单的邮件发送封装库(1) -- 使用Apache Commons Email
- U-Boot常用命令和常用环境变量
- android ListView异步加载图片,完美实现图文混排
- Tomcat启动分析(我们为什么要配置CATALINA_HOME环境变量)
- 关于使用echarts.js插件写的一个折线图demo
- 实现一个Assert类,用于测试使用
- 终端界面GUI开源项目charva -- 介绍
- document.execCommand()解析
- SWT实例学习代码例子 -- 学好swt,色色就可以写桌面应用了
- Appium移动自动化测试之Java篇
- Aspose.Cells单元格转换为数字格式
- WEB服务器、应用程序服务器、HTTP服务器区别【转】
- 日志库
- 上班了还能享受带薪长假,真爽啊 外企就是好啊!
- 屏蔽ViewPager的预加载
- Linux进程描述符——task_struct(初学者的简单学习)
- ssh-keygen 的man手册译文