赞
踩
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
private void DesCrypt(byte[] source, byte[] dest, byte[] key,int flg)
{
inti,h,j;
int t;
bytec1,c2;
byte[]buf = new byte[8] ;
byte[] buf1 = new byte[8];
byte[] destbuf = new byte[9];
h = 0 ;
/* 不满16位用FF填充 */
for( i=0; i
if( source[i] != 0)
h++;
}
if(h<16){
for(i=h;i<16;i++)
source[i]='F';
}
//source[16]=0;
for (i=0;i<16;i=i+2) {
/*字符转成十进制数字*/
if( is_digit( source[i] )){
c1 = (byte)(source[i]-'0') ;
}else if( is_xdigit(source[i] )){
c1 = (byte)(source[i]-'A'+10);
}else{
c1 = source[i];
}
if( is_digit( source[i+1] )){
c2 = (byte)(source[i+1]-'0') ;
}else if( is_xdigit(source[i+1] )){
c2 = (byte)(source[i+1]-'A'+10);
}else{
c2 = source[i+1];
}
buf[i/2]=(byte)(c1*0x10+c2);
/*密钥中的字符转换成十进制数字*/
if( is_digit(key[i])){
c1 = (byte)(key[i]-'0') ;
}else if(is_xdigit(key[i])){
c1 = (byte)(key[i]-'A'+10) ;
}else{
c1 = key[i] ;
}
if( is_digit(key[i+1])){
c2 = (byte)(key[i+1]-'0') ;
}else if(is_xdigit(key[i+1])){
c2 = (byte)(key[i+1]-'A'+10) ;
}else{
c2 = key[i+1] ;
}
buf1[i/2]=(byte)(c1*0x10+c2);
}
//Lke_des(buf,destbuf,buf1,flg);
destbuf = encrypt(buf, buf1);
for(i=0;i<8;i++){
if((destbuf[i]&0xFF) > 0x7f ){
dest[i*2] = 'F';
dest[i*2+1] = 'F';
continue;
}
String str = Integer.toHexString(destbuf[i]&0xFF).toUpperCase();
//System.out.println("str:"+str);
if(str.length() == 1)
{
dest[i*2+0] = (byte)("0".charAt(0));
dest[i*2+1] = (byte)(str.charAt(0));
}
else
{
dest[i*2+0] = (byte)(str.charAt(0));
dest[i*2+1] = (byte)(str.charAt(1));
}
//System.out.println("destbuf:"+destbuf);
//for(j=0; j
//dest[i*2+j] = (byte)(str.toUpperCase().charAt(j));
//}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。