2024年4月29日发(作者:)

SHA1加密算法(40位支持中文)VB6.0实例:

Form1窗体及代码如下:

Option Explicit

Private Sub Command1_Click()

= StringSHA1()

End Sub

通用模块代码如下:

'----------------------------------------------------------------------------------------------------------------------

----

'Attribute VB_Name = "SHA1"

Option Explicit

' TITLE:

' Secure Hash Algorithm, SHA-1

' AUTHORS:

' Adapted by Iain Buchan from Visual Basic code posted at Planet-Source-Code by Peter Girard

'

/xq/ASP/txtCodeId.13565/lngWId.1/qx/vb/scripts/

m

' PURPOSE:

' Creating a secure identifier from person-identifiable data

' The function SecureHash generates a 160-bit (20-hex-digit) message digest for a given message

(String).

' It is computationally infeasable to recover the message from the digest.

' The digest is unique to the message within the realms of practical probability.

' The only way to find the source message for a digest is by hashing all possible messages and

comparison of their digests.

' REFERENCES:

' For a fuller description see FIPS Publication 180-1:

' /fipspubs/

' SAMPLE:

' Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"

' Returns Digest: "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"

' Message: "abc"

' Returns Digest: "A9993E364706816ABA3E25717850C26C9CD0D89D"

Private Type Word

B0 As Byte

B1 As Byte

B2 As Byte

B3 As Byte

End Type

'Public Function idcode(cr As Range) As String

' Dim tx As String

' Dim ob As Object

' For Each ob In cr

' tx = tx & LCase(CStr(2))

' Next

' idcode = sha1(tx)

'End Function

Private Function AndW(w1 As Word, w2 As Word) As Word

AndW.B0 = w1.B0 And w2.B0

AndW.B1 = w1.B1 And w2.B1

AndW.B2 = w1.B2 And w2.B2

AndW.B3 = w1.B3 And w2.B3

End Function

Private Function OrW(w1 As Word, w2 As Word) As Word

OrW.B0 = w1.B0 Or w2.B0

OrW.B1 = w1.B1 Or w2.B1