Home > Software engineering >  VB source array exceeds the length
VB source array exceeds the length

Time:09-25

Private Sub Button2_Click (sender As Object, As EventArgs e) Handles btLg. Click
RFID.com m. iscardInBuffer ()
RFID.com m. iscardOutBuffer ()
Dim ReadBlock () As Byte={& amp; H6, & amp; HFF, & amp; H15, & amp; H0, & amp; H4}
Dim CheckSum As Byte
Dim x As Integer

For x=0 To ReadBlock. Length - 1
CheckSum=CheckSum Xor ReadBlock (x)
Next
ReDim Preserve ReadBlock (ReadBlock. Length)

ReadBlock (ReadBlock. Length - 1)=CheckSum

RFID.com m. rite (ReadBlock, 0, ReadBlock Length)

System. The Threading. Thread.sleep (200)
Dim intBytesToRead As Integer=RFID.com m.B ytesToRead
Dim DataIn (intBytesToRead - 1) As Byte
RFID.com m.R ead (DataIn, 0, intBytesToRead)

'extract the MD5 from the tag, and save into a new byte array
Dim MD5FromTag (15) As Byte
Array. Copy (MD5FromTag DataIn, 4, 0, 16)
prompt here beyond the length of the source array (An unhandled exception of type 'System. ArgumentException' occurred in mscorlib. DLL

Additional information: the source array length is insufficient, please check the srcIndex and length as well as the lower limit of an array,)

Dim key As String=tbuser. Text & amp; Tbpassword. Text

Dim md5cp As New MD5CryptoServiceProvider
Dim Encryptionkey As Byte ()=md5cp.Com puteHash (Encoding. UTF8. GetBytes (key))

Dim blnMatch=VerifyMD5 (MD5FromTag Encryptionkey)

If blnMatch=True Then
Form1. The Show ()
Me. Hide ()
The Else
MsgBox (" It does not work ")
End the If


End Sub

CodePudding user response:

 Array. Copy (MD5FromTag DataIn, 4, 0, 16) 

This should put the DataIn (4) ~ DataIn copies the contents of (19) to MD5FromTag (0) ~ MD5FromTag (15)
DataIn length has 20, didn't you see check the length of the code, how do you guarantee?
  • Related