PB中的加密解密的方法
第一次来这里,如果在这里能交几个好友,我会很开心的,我是刚学PB的,闲着没事把PB中加密解密的方法研究了一个,看来PB中加密解密的方法还是不复杂的,就做了以下几个函数。发给大家共享一下。我的QQ:307679136,QQ群号:30657445 。希望大家能多联系。共同提高。
/*******************************************************************
函数名称:f_decryptpbpassword()
参数: as_orginalpassword string 原始密码
返回值: string 解密后文本
功能描述:解密PB数据库连接描述密码
*******************************************************************/
string ls_temp,ls_return=''
integer i,li_count,li_ascii
if len(as_orginalpassword) < 2 or as_orginalpassword = '00' then return ''
as_orginalpassword = left(reverse(as_orginalpassword),len(as_orginalpassword) - 2)
li_count = ceiling(len(as_orginalpassword) / 2)
for i = 1 to li_count
ls_temp = mid(as_orginalpassword,(i - 1) * 2 + 1,2)
li_ascii =of_hextodecimal(ls_temp)
ls_temp = char(li_ascii)
ls_return = ls_return + ls_temp
next
return ls_return
/*******************************************************************
函数名称:f_encryptpbpassword()
参数: as_newpassword string 原始密码
返回值: string 解密后文本
功能描述:加密PB数据库连接描述密码
*******************************************************************/
string ls_temp,ls_return='00'
integer i,li_count,li_ascii
if len(as_newpassword)=0 or as_newpassword = '' then return '00'
as_newpassword = reverse(as_newpassword)
li_count = len(as_newpassword)
for i = 1 to li_count
li_ascii = asc(mid(as_newpassword,i,1))
ls_temp= of_decimaltohex(li_ascii)
ls_return =ls_temp+ls_return
next
return reverse(ls_return)
/*******************************************************************
函数名称:of_decimaltohex()
参数: as_decicmaldata unsignedlong 十进制数
返回值: string 十六进制数
功能描述:十进制转十六进制
*******************************************************************/
string ls_hex,li_hex[ 0 to 15]
unsignedlong lul_decimal
integer i
for i = 0 To 9
li_hex[i] = string(i)
next
for i = 10 To 15
li_hex[i] =char(55+i)
next
do while as_decicmaldata>0
lul_decimal=mod(as_decicmaldata,16)
as_decicmaldata=int(as_decicmaldata/16)
choose case lul_decimal
case 0 to 15
ls_hex=li_hex[lul_decimal]+ls_hex
case else
return lower(ls_hex)
end choose
loop
return lower(ls_hex)
/*******************************************************************
函数名称:of_hextodecimal()
参数: as_hexdata string 十六进制数
返回值: unsignedlong 十进制数
功能描述:十六进制转十进制
*******************************************************************/
char lch_char[]
unsignedlong lul_decimal=0
integer li_dec[48 to 70], i, li_len
for i = 48 To 57
li_dec[i] = i - 48
next
for i = 65 To 70
li_dec[i] = i - 55
next
as_hexdata = upper(as_hexdata)
lch_char = as_hexdata
li_len = len (as_hexdata)
for i = 1 to li_len
choose case lch_char[i]
case '0' to '9', 'A' to 'F'
lul_decimal = lul_decimal * 16 + li_dec[asc(lch_char[i])]
case else
return lul_decimal
end choose
next
return lul_decimal