tags:

views:

122

answers:

1

I am getting the error "invalid procedure call or arguments" at the step computeHash(). Any help highly appreciated.

Private Sub Form_Load()

Dim rngcsp As New RNGCryptoServiceProvider '= new RNGCryptoServiceProvider()

Dim u8 As Encoding   

'u8 = Encoding.UTF8

Dim minSaltSize As Integer
Dim maxSaltSize As Integer
Dim saltSize As Integer

minSaltSize = 4
maxSaltSize = 8
Dim randm As Random

Set randm = New Random

Dim saltBytes() As Byte
ReDim saltBytes(saltSize)    

Set rngcsp = New RNGCryptoServiceProvider
rngcsp.GetNonZeroBytes (saltBytes)

Dim plainTextBytes() As Byte
plainTextBytes() = ConvertStringToUtf8Bytes("Mohan")

Dim plainTextBytesLen As Long
plainTextBytesLen = UBound(plainTextBytes) - LBound(plainTextBytes) + 1

Dim saltBytesLen As Long
saltBytesLen = UBound(saltBytes) - LBound(saltBytes) + 1

Dim plainTextWithSaltBytes() As Byte

ReDim plainTextWithSaltBytes(plainTextBytesLen + saltBytesLen)

For i = 0 To plainTextBytesLen - 1
    plainTextWithSaltBytes(i) = plainTextBytes(i)
Next    

For i = 0 To saltBytesLen - 1
    plainTextWithSaltBytes(i) = saltBytes(i)
Next

'Dim hash As HashAlgorithm = New MD5CryptoServiceProvider()    
Dim hash12 As New SHA256Managed

'SHA256Managed

 Dim totLen As Integer
 totLen = plainTextBytesLen + saltBytesLen

 Dim str As String
 Dim hashBytes() As Byte
 'With
 hashBytes = hash12.computeHash(plainTextWithSaltBytes)     ', 0, totLen)
 'End With

End Sub

A: 

I didn't read this code carefully, but it might be a simple confusion about array bounds. The line:

   ReDim plainTextWithSaltBytes(plainTextBytesLen + saltBytesLen)

...creates an array one byte longer than maybe you think it does.

Jim Mack