Visual Basic 6.0 - неправильный вызов процедуры ComputeHash или ошибка аргумента - PullRequest
0 голосов
/ 07 февраля 2010

Я получаю ошибку "Недопустимый вызов процедуры или аргументы" на шаге computeHash().

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

1 Ответ

0 голосов
/ 10 февраля 2010

Я не читал этот код внимательно, но это может быть простая путаница в отношении границ массива. Линия:

   ReDim plainTextWithSaltBytes(plainTextBytesLen + saltBytesLen)

... создает массив на один байт длиннее, чем, возможно, вы думаете.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...