DES 加解密的封装和 使用的例子__教程 |
|
日期:2007-5-20 0:36:15 人气:73 [大 中 小] |
|
|
|
DES加解密使用样例
package org.jtool.desutils;/** * */public class DESTest { public static void main(String[] args) throws Exception { String key = "ABCDEFGH"; String value = "AABBCCDDEE"; DESEncrypt desEncrypt = new DESEncrypt(key.getBytes()); byte[] encryptText = desEncrypt.doEncrypt(value.getBytes()); System.out.println("doEncrypt - " + toHexString(encryptText)); System.out.println("doEncrypt - " + new String(encryptText)); DESDecrypt desDecrypt = new DESDecrypt(key.getBytes()); byte[] decryptText = desDecrypt.doDecrypt(encryptText); System.out.println("doDecrypt - " + new String(decryptText)); System.out.println("doDecrypt - " + toHexString(decryptText)); } /** * 16进制显示数据 * * @param value 字节数组 * @return */ public static String toHexString(byte[] value) { String newString = ""; for (int i = 0; i < value.length; i++) { byte b = value[i]; String str = Integer.toHexString(b); if (str.length() > 2) { str = str.substring(str.length() - 2); } if (str.length() < 2) { str = "0" + str; } newString += str; } return newString.toUpperCase(); }} |
|
出处:本站原创 作者:佚名 |
|
|