2010-02-07 110 views
0

我在步驟computeHash()處收到錯誤「無效過程調用或參數」。Visual Basic 6.0 - ComputeHash無效過程調用或參數錯誤

私人小組的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 

末次

回答

0

我沒仔細看這段代碼,但它可能是關於數組邊界簡單的混亂。該行:

ReDim plainTextWithSaltBytes(plainTextBytesLen + saltBytesLen) 

...創建一個數組比您想象的要長一個字節。

相關問題