·您当前的位置:首页 > 技术教程 > JavaScript >

[JS]DES加密封装和DES解密封装(3)

时间:2014-09-23 17:15酷播
DES加解密使用样例 package org.jtool.desutils; /** * */ public class DESTest { public static void main(String[] args) throws Exception { String key = ABCDEFGH; String value = AABBCCDDEE; DESEncrypt de


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();
}
}

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器