VB中實現(xiàn)MD5加密
' /* Zeroize sensitive information.
'*/
' MD5_memset ((POINTER)x, 0, sizeof (x));
End Sub
Private Sub Decode(Length As Integer, OutputBuffer() As Long, InputBuffer() As Byte)
Dim intDblIndex As Integer
Dim intByteIndex As Integer
Dim dblSum As Double
intDblIndex = 0
For intByteIndex = 0 To Length - 1 Step 4
dblSum = InputBuffer(intByteIndex) + _
InputBuffer(intByteIndex + 1) * 256# + _
InputBuffer(intByteIndex + 2) * 65536# + _
InputBuffer(intByteIndex + 3) * 16777216#
OutputBuffer(intDblIndex) = UnsignedToLong(dblSum)
intDblIndex = intDblIndex + 1
Next intByteIndex
End Sub
'
' FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' Rotation is separate from addition to prevent recomputation.
'
Private Function FF(a As Long, _
b As Long, _
c As Long, _
d As Long, _
x As Long, _
s As Long, _
ac As Long) As Long
a = LongOverflowAdd4(a, (b And c) Or (Not (b) And d), x, ac)
a = LongLeftRotate(a, s)
a = LongOverflowAdd(a, b)
End Function
Private Function GG(a As Long, _
b As Long, _
c As Long, _
d As Long, _
x As Long, _
s As Long, _
ac As Long) As Long
a = LongOverflowAdd4(a, (b And d) Or (c And Not (d)), x, ac)
a = LongLeftRotate(a, s)
a = LongOverflowAdd(a, b)
End Function
Private Function HH(a As Long, _
b As Long, _
c As Long, _
d As Long, _
x As Long, _
s As Long, _
ac As Long) As Long
a = LongOverflowAdd4(a, b Xor c Xor d, x, ac)
a = LongLeftRotate(a, s)
a = LongOverflowAdd(a, b)
End Function
Private Function II(a As Long, _
b As Long, _
c As Long, _
d As Long, _
x As Long, _
s As Long, _
ac As Long) As Long
a = LongOverflowAdd4(a, c Xor (b Or Not (d)), x, ac)
a = LongLeftRotate(a, s)
a = LongOverflowAdd(a, b)
End Function