public static String strToDes(String strData1,String strKey1){
int bytelen1 = strData1.getBytes().length;
byte[] result1 = new byte[(bytelen1 + 8) - (bytelen1 % 8)];
byte[] bytekey1 = strKey1.getBytes();
byte[] bytedata1 = strData1.getBytes();
String strEjz01,strSLjz01;
String strSLjz02 = "";
DES des001 = new DES();
result1 = des001.DesEncrypt(bytekey1, bytedata1, 1);//加密函数
for(int i01 = 0;i01 < result1.length;i01++){
strEjz01 = Integer.toBinaryString(Math.abs(result1[i01]));
strEjz01 = "00000000" + strEjz01;
strEjz01 = strEjz01.substring(strEjz01.length()-7, strEjz01.length());
if(result1[i01]<0){
strEjz01 = "1" + strEjz01;
}
else{
strEjz01 = "0" + strEjz01;
}
strSLjz01 = Integer.toHexString(Integer.parseInt(Integer.valueOf(strEjz01,2).toString()));//整数到十六进制数
strSLjz01 = "00" + strSLjz01;
strSLjz01 = strSLjz01.substring(strSLjz01.length()-2,strSLjz01.length());
strSLjz02 = strSLjz02 + strSLjz01;
}
String result001 = strSLjz02.toUpperCase();
return result001;
}
|