各位大侠,我要把表的某些记录加密,加密可逆,要能对加密后的字段进行糊模查询,最好加密后是16进制的字符。
我要把表的某些记录加密,加密可逆,要能对加密后的字段进行糊模查询,最好加密后是16进制的字符。
字段的内容有中文数字和其它字符。
请高手来指点一下,给点代码。
加解密都在程序里,我是用CB开发
我自己写了一个最简单的,但是会出错,还没有找出错在那里,请大家来帮帮忙
代码如下:
String StrToHex(String sSrc)
{ //String换成16进制字符串
if(sSrc.IsEmpty())
{
return "";
}
String sTmp;
String sDes = "";
Byte * bBuf = new Byte[sSrc.Length()];
int nLen = sSrc.Length();
StrPCopy(bBuf,sSrc);
for (int i=0; i<nLen; i++)
{
sTmp.sprintf("%x",bBuf[i]);
sDes += sTmp;
}
delete[] bBuf;
return sDes;
}
//////////////////////////////////////////////////////////////////////////////
String HexToStr(String sSrc,int iKey = 6)
{ //16进制字符串还原String
if(sSrc.IsEmpty())
{
return "";
}
String sDec;
String sTmp;
int nLen = sSrc.Length();
Byte* cDesc = new Byte[nLen/2+1];
int i;
for(i=0; i<nLen/2; i++)
{
sTmp = "0x";
sTmp += sSrc.SubString(i*2+1,2);
cDesc[i] = StrToInt(sTmp);
}
cDesc[i] = '\0';
sDec.sprintf("%s",cDesc);
delete[] cDesc;
return sDec;
}