1 / 19
文档名称:

AES对称加密例子.doc

格式:doc   大小:92KB   页数:19页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

AES对称加密例子.doc

上传人:yuzonghong1 2017/2/23 文件大小:92 KB

下载得到文件列表

AES对称加密例子.doc

文档介绍

文档介绍:1什么是 AES AES 是一种对称的私钥加密技术。它支持 128 ,192 ,256 位加密。 2AES 和 Java 开始,集成了 JCE 包。现在的 java 支持 128 位key 的加密。(下面的程序也是以 128 位为例讲解的) 3如何使用 JCE 例 Java 代码 import .*; import .*; import .*; import .*; /** *This program generates aAES key, retrieves its raw bytes, and *then reinstantiates aAES key from the key bytes. *The reinstantiated key isused toinitialize aAES cipher for *encryption and decryption. */public class AES {/** *Turns array ofbytes into string *****@param buf Array ofbytes toconvert tohex string ****@return Generated hex string */public static String asHex (byte buf[]) { StringBuffer strbuf =new StringBuffer( *2); int i; for (i=0;i<; i++) { if(((int) buf[i] &0xff) <0x10) ("0"); (((int) buf[i] &0xff, 16)); }return (); }public static void main(String[] args) throws Exception { String message="This isjust anexample"; //Get the KeyGenerator KeyGenerator kgen =("AES"); (128); //192 and 256 bits may not beavailable //Generate the secret key specs. SecretKey skey =(); byte[] raw =(); SecretKeySpec skeySpec =new SecretKeySpec(raw, "AES"); //Instantiate the cipher Cipher cipher =("AES"); (, skeySpec); byte[] encrypted =(( ==0? "This isjust anexample" :args[0]).getBytes()); ("encrypted string: "+asHex(encrypted)); (, skeySpec); byte[] original =(encrypted); String originalString =new String(original); ("Original string: "+ originalString +""+asHex(original)); }}import .*; import .*; import .*; import .*; /** *This program generates aAES key, retrieves its raw bytes, and *then reinstantiates aAES key from the key bytes. *The reinstantiated key isused toinitialize aAES cipher for *encryption