[JS]DES加密封装和DES解密封装(3)
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();
}
}
热门文章推荐
- [JS]window.location获取url各项参数详解
- [JS]jQuery,javascript获得网页的高度和宽度
- [JS]视频弹窗视频弹出层videoLightBox(含三种播放器的用法)
- [JS]JS提交中文encodeURI两次转码
- [JS]js版方面encodeURI转码和decodeURI解码的用法实例
- [JS]js取当前机子的时间戳实例
- [JS]AES加密(基于crypto-js)PHP后端解密
- [JS]data:image/png;base64写法的用途及说明
请稍候...