日期:2014-05-16 浏览次数:20362 次
是个DES算法.....但是又不同...求解!!这个用winform程序能调用么.或者谁有相关的C#调用..能详细解答我的重谢 function enString(data){ var key1 = "YHXWWLKJYXGS"; var key2 = "ZFCHHYXFL10C"; var key3 = "DES"; var enchex = strEnc(data,key1,key2,key3); return enchex; } /** * DES加密/解密 * @Copyright Copyright (c) 2009 * @author linsi */ /* * encrypt the string to string made up of hex * return the encrypted string */ function strEnc(data,firstKey,secondKey,thirdKey){ var leng = data.length; var encData = ""; var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength; if(firstKey != null && firstKey != ""){ firstKeyBt = getKeyBytes(firstKey); firstLength = firstKeyBt.length; } if(secondKey != null && secondKey != ""){ secondKeyBt = getKeyBytes(secondKey); secondLength = secondKeyBt.length; } if(thirdKey != null && thirdKey != ""){ thirdKeyBt = getKeyBytes(thirdKey); thirdLength = thirdKeyBt.length; } if(leng > 0){ if(leng < 4){ var bt = strToBt(data); var encByte ; if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){ var tempBt; var x,y,z; tempBt = bt; for(x = 0;x < firstLength ;x ++){ tempBt = enc(tempBt,firstKeyBt[x]); } for(y = 0;y < secondLength ;y ++){ tempBt = enc(tempBt,secondKeyBt[y]); } for(z = 0;z < thirdLength ;z ++){ tempBt = enc(tempBt,thirdKeyBt[z]); } encByte = tempBt; }else{ if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){ var tempBt; var x,y; tempBt = bt; for(x = 0;x < firstLength ;x ++){ tempBt = enc(tempBt,firstKeyBt[x]); } for(y = 0;y < secondLength ;y ++){ tempBt = enc(tempBt,secondKeyBt[y]); } encByte = tempBt; }else{ if(firstKey != null && firstKey !=""){ var tempBt; var x = 0; tempBt = bt; for(x = 0;x < firstLength ;x ++){ tempBt = enc(tempBt,firstKeyBt[x]); } encByte = tempBt; } } } encData = bt64ToHex(encByte); }else{ var iterator = parseInt(leng/4); var remainder = leng%4; var i=0; for(i = 0;i < iterator;i++){ var tempData = data.substring(i*4+0,i*4+4); var tempByte = strToBt(tempData); var encByte ; if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){ var tempBt; var x,y,z; tempBt = tempByte; for(x = 0;x < firstLength ;x ++){ tempBt = enc(tempBt,firstKeyBt[x]); } for(y = 0;y < secondLength ;y ++){ tempBt = enc(tempBt,secondKeyBt[y]); } for(z = 0;z < thirdLength ;z ++){ tempBt = enc(tempBt,thirdKeyBt[z]); } encByte = tempBt; }else{ if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){ var tempBt; var x,y; tempBt = tempByte; for(x = 0;x < firstLength ;x ++){ tempBt = enc(tempBt,firstKeyBt[x]); } for(y = 0;y < secondLength ;y ++){ tempBt = enc(tempBt,secondKeyBt[y]); } encByte = tempBt