【发布时间】:2015-08-14 00:01:50
【问题描述】:
重新开始不是一个选项,因为已经运行的项目使用 SHA-256
这是 java 代码 --->>> 只是一个简单的代码来散列任何字符串
public static String SHA256 (String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
{
textByte = text.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("SHA-256");
textByte = md.digest(textByte);
return Base64.encodeToString(textByte,Base64.NO_CLOSE);
}
和VB代码如下
Public Function EncryptPassword(ByVal password As String) As String
Dim hashedPassword As String = Nothing
Dim hashProvider As SHA256Managed = Nothing
Try
Dim passwordBytes() As Byte
passwordBytes = System.Text.Encoding.Unicode.GetBytes(password)
hashProvider = New SHA256Managed
hashProvider.Initialize()
passwordBytes = hashProvider.ComputeHash(passwordBytes)
hashedPassword = Convert.ToBase64String(passwordBytes)
Catch ex As Exception
Finally
If Not hashProvider Is Nothing Then
hashProvider.Clear()
hashProvider = Nothing
End If
End Try
Return hashedPassword
End Function
【问题讨论】:
-
不确定这是否会导致您的问题,但 Java 中的 'byte' 已签名,因此它相当于 VB 中的 'SByte',而不是 'Byte'。