急:关于加密字符串存入数据库image型字段,在线等待(可无限加分)(200分)

  • 主题发起人 主题发起人 spdavid
  • 开始时间 开始时间
S

spdavid

Unregistered / Unconfirmed
GUEST, unregistred user!
sybase 有一个字段dbuserinfo为image型字段

现有VB的加密解密方法如下:

Function toString(ByVal asDb As Variant) As String
'==================================================================
'本用下句,但WEB方式不可用byref,故放弃
'Function toString1(ByVal asDb As Variant, ByRef asPwd As String) As String
'==================================================================
'Description: 把blob解密后放入字符串
'
' Note: 加密algorithm: 头尾放字符串长度(整数),中间按顺序放每个字符
' 的ASCII码加字符顺序号的平方形成的整数

'输入:解密前BLOB值
'输出:错误信息;解密后的STRING
'==================================================================
Dim li_len As Integer, i As Integer, li_ascii As Integer

Dim ll_pos As Long, lb_tmp() As Byte

Dim asPwd As String, asRet As String

asRet = ""
ll_pos = 1
lb_tmp = MidB(asDb, ll_pos, 2)
ll_pos = ll_pos + 2
li_len = CInt(lb_tmp(0))
If li_len > 30 Then
asRet = "数据库中密码字符数目大于30,不允许"
Else
asPwd = ""

For i = 1 To li_len
lb_tmp = MidB(asDb, ll_pos, 2)
ll_pos = ll_pos + 2
asPwd = asPwd + Chr(CInt(lb_tmp(0)) - i * i)
Next

lb_tmp = MidB(asDb, ll_pos, 2)
ll_pos = ll_pos + 2
If li_len <> CInt(lb_tmp(0)) Then
asRet = "数据库中密码字符首尾存放的串长度不同,不允许"
End If
End If

toString = asRet + ";" + asPwd


End Function

Function ToBlob(asPwd As String) As Variant
'==================================================================
'Description: 把输入字符串放入blob
'
' Note: 加密algorithm: 头尾放字符串长度(整数),中间按顺序放每个字符
' 的ASCII码加字符顺序号的平方形成的整数
'
'输入:加密前的STRING值,加密后的值--返回值,
'输出:错误信息 "":成功
'==================================================================
Dim li_len As Integer, i As Integer, li_ascii As Integer

Dim ll_pos As Long
Dim ib_128(128) As Byte

If IsNull(asPwd) Then ToBlob = ""

li_len = Len(asPwd)
If li_len > 30 Then ToBlob = ""

ll_pos = 0
'll_pos = MidB(ib_128, ll_pos, li_len)
ib_128(0) = li_len
ll_pos = ll_pos + 2
For i = 1 To li_len
li_ascii = Asc(Mid(asPwd, i, 1)) + i * i
'll_pos = MidB(ib_128, ll_pos, li_ascii)
ib_128(ll_pos) = li_ascii
ll_pos = ll_pos + 2
Next

'll_pos = MidB(ib_128, ll_pos, li_len)
ib_128(ll_pos) = li_len
ll_pos = ll_pos + 2

ToBlob = ib_128


End Function


////////////////////////////////////////////////////////////

求高手帮忙转换成delphi的方法,并能写入和读取数据库中的image型字段

小生在线等待
 
这么长,还得细看一看
 
to smallsun007: 谢谢关注,实话说解码过程都差不多了,就用流的方法写数据库有问题

to yanghai0437: 谢谢踢贴
 
把他写到流里,然后写如数据库中
query. Sql.Add('INSERT INTO aa VALUES (:xx)');
query.ParamByName('xx').loadfromstream(stream);
 
to cjsam:能说的详细一点,给个代码看看好不
 
紧急等待中。。。。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
576
import
I
后退
顶部