Function mySHA(ByVal SourceStr As String) As String 'SHA1加密算法
Dim SHA As New System.Security.Cryptography.SHA1CryptoServiceProvider 'sha1加密
'Dim sha As New System.Security.Cryptography.SHA256Managed'sha256加密
'Dim sha As New System.Security.Cryptography.SHA512Managed 'sha512加密
Dim bytValue() As Byte '输入
Dim bytHash() As Byte '输出
bytValue = System.Text.Encoding.UTF8.GetBytes(SourceStr) '输入字符转为byte
bytHash = SHA.ComputeHash(bytValue) '加密
SHA.Clear()
mySHA = Convert.ToBase64String(bytHash) '转为字符
End Function
Dim SHA As New System.Security.Cryptography.SHA1CryptoServiceProvider 'sha1加密
'Dim sha As New System.Security.Cryptography.SHA256Managed'sha256加密
'Dim sha As New System.Security.Cryptography.SHA512Managed 'sha512加密
Dim bytValue() As Byte '输入
Dim bytHash() As Byte '输出
bytValue = System.Text.Encoding.UTF8.GetBytes(SourceStr) '输入字符转为byte
bytHash = SHA.ComputeHash(bytValue) '加密
SHA.Clear()
mySHA = Convert.ToBase64String(bytHash) '转为字符
End Function

本文介绍了一种使用Visual Basic实现的SHA1加密算法。通过创建SHA1CryptoServiceProvider对象完成加密过程,并将原始字符串转换为UTF-8编码的字节数组,接着利用SHA1算法进行加密处理,最后将加密后的字节数组转换为Base64字符串形式。
382

被折叠的 条评论
为什么被折叠?



