当前位置: 网学 > 编程文档 > ASP > 正文

ASP 改良版MD5、SHA256多重加密类(二次及多次)

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/16

Private Function AddUnsigned(byVal lX, byVal lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddUnsigned = lResult
End Function

''MD5_FF,MD5_GG,MD5_HH,MD5_II MD5主编码函数
Private Sub MD5_FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub MD5_GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub MD5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub MD5_II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

''MD5_F,MD5_G,MD5_H,MD5_I MD5辅编码函数
Private Function MD5_F(x, y, z)
MD5_F = (x And y) or ((Not x) And z)
End Function
Private Function MD5_G(x, y, z)
MD5_G = (x And z) or (y And (Not z))
End Function
Private Function MD5_H(x, y, z)
MD5_H = (x Xor y Xor z)
End Function
Private Function MD5_I(x, y, z)
MD5_I = (y Xor (x or (Not z)))
End Function

''16进制编码转换
Private Function WordToHex(byVal lValue)
Dim lByte
Dim lCount
For lCount = 0 To 3
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And MD5_m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
Next
End Function

''MD5主函数 MD5(字符串,编码位)
Public Function MD5(byVal sMessage, byVal sType)
Dim x
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim a
Dim b
Dim c
Dim d
Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21
x = ConvertToWordArray(sMessage) ''加密步骤1:数组转换
a = &H67452301
b = &HEFCDAB89
c = &H98BADCFE
d = &H10325476
For k = 0 To UBound(x) Step 16
AA = a
BB = b
CC = c
DD = d
''加密步骤2:编码转换
MD5_FF a, b, c, d, x(k + 0), S11, &HD76AA478
MD5_FF d, a, b, c, x(k + 1), S12, &HE8C7B756
MD5_FF c, d, a, b, x(k + 2), S13, &H242070DB
MD5_FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
MD5_FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
MD5_FF d, a, b, c, x(k + 5), S12, &H4787C62A
MD5_FF c, d, a, b, x(k + 6), S13, &HA8304613
MD5_FF b, c, d, a, x(k + 7), S14, &HFD469501
MD5_FF a, b, c, d, x(k + 8), S11, &H698098D8
MD5_FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
MD5_FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
MD5_FF b, c, d, a, x(k + 11), S14, &H895CD7BE
MD5_FF a, b, c, d, x(k + 12), S11, &H6B90

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号