2007年12月26日 星期三

AzDG可逆加密演算法 for VB ASP

最近的案子中需要跨網站交換資料
明碼交換有點不安全
所以得使用可逆加密算法來加密資料
在google中找到了Azerbaijan Development Group(AzDG)
開發的可逆加密算法 AzDGCrypt
這是一套滿棒的可逆加密算法
而且需要使用私匙來加密數據
對我而言,剛好可以給要交換資料的網站每個人一把私匙
這樣就不用擔心a網站的資料b網站也解的開
google中找的到各種版本的AzDG加密算法
找不到For VB ASP版
所以自己動手翻成VB ASP版

下列程式需注意,缺少了base64和md5的function
版權問題,請自行尋找替換
Base64Encode
base64_decode
md5


'私匙
PrivateKey = "qaz"
function encode(arg_strSourceText)
strKeyMd5 = md5(PrivateKey,32) '自行尋找md5算法
intCRCLength = 0
strTmp = ""
intTextLength = Len(arg_strSourceText)
For i = 1 To intTextLength
If (intCRCLength > 31) Then
intCRCLength = 0
End If
strTmp = strTmp & Chr(Asc(Mid(arg_strSourceText,i,1)) xor Asc(Mid(strKeyMd5,intCRCLength+1,1)))
intCRCLength = intCRCLength + 1
Next
encode = strTmp
End Function

Function AzDG_crypt(arg_strSourceText)
Randomize()
strRandMd5 = md5(CInt(Int((32000 * Rnd()))),32)
intCRCLength = 0
strTmp = ""
intTextLength = Len(arg_strSourceText)
For i = 1 To intTextLength
If (intCRCLength > 31) Then
intCRCLength = 0
End If
chrMd5 = Mid(strRandMd5,intCRCLength+1,1)
strTmp = strTmp & (chrMd5 & (Chr(Asc(Mid(arg_strSourceText,i,1)) Xor Asc(chrMd5)))) intCRCLength = intCRCLength + 1
Next
AzDG_crypt = Base64Encode(encode(strTmp)) '自行尋找base64加密算法
End Function

Function AzDG_decrypt(arg_strSourceText)
arg_strSourceText = encode(base64_decode(arg_strSourceText)) '自行尋找base64解密算法
strTmp = ""
intTextLength = Len(arg_strSourceText)
For i = 1 To intTextLength
md5char = Mid(arg_strSourceText,i,1)
i = i + 1
strTmp = strTmp & Chr(Asc(mid(arg_strSourceText,i,1)) Xor Asc(md5char))
Next
AzDG_decrypt = strTmp
End Function

1 則留言:

匿名 提到...

不好意思,能請您私底下提供一下 base64Encode/Decode & MD5 部份的 source code 嗎?

感謝!

mail:clark_159@yahoo.com.tw