Hi. I'm having this problem regarding hashing the string passed into the function. It keeps giving me the exception "Invalid length for Base-64 char array". How do I calculate the length of the byte array required?
The exception occurs at the line:
"bteInputByteArray = Convert.FromBase64String(strToHash)"
The following is the function's code:
Public Shared Function MD5Hash(ByVal strToHash As String) As String
Dim md5HashSP As New MD5CryptoServiceProvider()
Dim bteInputByteArray(strToHash.Length) As Byte
Dim bteOutputByteArray() As Byte
Try
'Exception occurs here.
bteInputByteArray = Convert.FromBase64String(strToHash)
bteOutputByteArray = md5HashSP.ComputeHash(bteInputByteArray)
Dim encUTF8 As Encoding = Encoding.UTF8
Return encUTF8.GetString(bteOutputByteArray)
Catch e As Exception
Return String.Empty
End Try
End Function
Thanks in advance!
The exception occurs at the line:
"bteInputByteArray = Convert.FromBase64String(strToHash)"
The following is the function's code:
Public Shared Function MD5Hash(ByVal strToHash As String) As String
Dim md5HashSP As New MD5CryptoServiceProvider()
Dim bteInputByteArray(strToHash.Length) As Byte
Dim bteOutputByteArray() As Byte
Try
'Exception occurs here.
bteInputByteArray = Convert.FromBase64String(strToHash)
bteOutputByteArray = md5HashSP.ComputeHash(bteInputByteArray)
Dim encUTF8 As Encoding = Encoding.UTF8
Return encUTF8.GetString(bteOutputByteArray)
Catch e As Exception
Return String.Empty
End Try
End Function
Thanks in advance!