Des加密(js+java结果一致)精讲

上传人:206****923 文档编号:90600525 上传时间:2019-06-13 格式:DOC 页数:28 大小:211.04KB
返回 下载 相关 举报
Des加密(js+java结果一致)精讲_第1页
第1页 / 共28页
Des加密(js+java结果一致)精讲_第2页
第2页 / 共28页
Des加密(js+java结果一致)精讲_第3页
第3页 / 共28页
Des加密(js+java结果一致)精讲_第4页
第4页 / 共28页
Des加密(js+java结果一致)精讲_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《Des加密(js+java结果一致)精讲》由会员分享,可在线阅读,更多相关《Des加密(js+java结果一致)精讲(28页珍藏版)》请在金锄头文库上搜索。

1、Des加密(js+java结果一致)正文:1.des资源文件下载(des.js+des.html+des.java) function getResult() /待加密字符串 var str = document.getElementById(str).innerText; /第一个参数必须;第二个、第三个参数可选 var key1 = document.getElementById(key1).innerText; var key2 = document.getElementById(key2).innerText; var key3 = document.getElementById(ke

2、y3).innerText; /加密方法 var enResult = strEnc(str,key1,key2,key3); /解密方法 var deResult = strDec(enResult,key1,key2,key3); /展示结果 document.getElementById(enStr).innerText = enResult; document.getElementById(dnStr).innerText = deResult; 字符串: admin 加密key: key1=1;key2=2;key3=3 加密结果: 解密结果: 4.java文件(des.java)p

3、ackage com.zz.test;import java.util.ArrayList;import java.util.List;public class Des public Des() public static void main(String args) Des desObj = new Des(); String key1 = 1; String key2 = 2; String key3 = 3; String data = admin; String str = desObj.strEnc(data, key1, key2, key3); System.out.printl

4、n(str); String dec = desObj.strDec(str, key1, key2, key3); System.out.println(dec); /* * DES加密/解密 * * Copyright Copyright (c) 2006 * author Guapo * see DESCore */ /* * encrypt the string to string made up of hex return the encrypted string */ public String strEnc(String data, String firstKey, String

5、 secondKey, String thirdKey) int leng = data.length(); String encData = ; List firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null; int firstLength = 0, secondLength = 0, thirdLength = 0; if (firstKey != null & firstKey != ) firstKeyBt = getKeyBytes(firstKey); firstLength = firstKeyBt.size(); i

6、f (secondKey != null & secondKey != ) secondKeyBt = getKeyBytes(secondKey); secondLength = secondKeyBt.size(); if (thirdKey != null & thirdKey != ) thirdKeyBt = getKeyBytes(thirdKey); thirdLength = thirdKeyBt.size(); if (leng 0) if (leng 4) int bt = strToBt(data); int encByte = null; if (firstKey !=

7、 null & firstKey != & secondKey != null & secondKey != & thirdKey != null & thirdKey != ) int tempBt; int x, y, z; tempBt = bt; for (x = 0; x firstLength; x+) tempBt = enc(tempBt, (int) firstKeyBt.get(x); for (y = 0; y secondLength; y+) tempBt = enc(tempBt, (int) secondKeyBt.get(y); for (z = 0; z th

8、irdLength; z+) tempBt = enc(tempBt, (int) thirdKeyBt.get(z); encByte = tempBt; else if (firstKey != null & firstKey != & secondKey != null & secondKey != ) int tempBt; int x, y; tempBt = bt; for (x = 0; x firstLength; x+) tempBt = enc(tempBt, (int) firstKeyBt.get(x); for (y = 0; y secondLength; y+) tempBt = enc(tempBt, (int) secondKeyBt.get(y); encByte = tempBt; else if (firstKey != null & firstKey != ) int tempBt; int x = 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号