title: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt" blowfish in vb.net
body: <p>I am using the following code</p>
  
  <p>This error occurs :</p>
  
  <p>Attempted to read or write protected memory. This is often an indication that other memory is corrupted. Attempted to read or write to protected memory. This is often an indication that other memory is corrupted.</p>
  
  <pre><code> Public Function PadBytes(abData() As Byte) As Object
  
      Dim nLen As Long
      Dim nPad As Integer
      Dim abPadded() As Byte
      Dim i As Long
  
      'Set up error handler for empty array
      On Error GoTo ArrayIsEmpty
  
      nLen = UBound(abData) - LBound(abData) + 1
      nPad = ((nLen \ 8) + 1) * 8 - nLen
  
      ReDim Preserve abPadded(nLen + nPad - 1)  ' Pad with # of pads (1-8)
      If nLen &gt; 0 Then
          CopyMemory(abPadded(0), abData(0), nLen)
      End If
  
      For i = nLen To nLen + nPad - 1
          abPadded(i) = CByte(nPad)
      Next
  
   ArrayIsEmpty:
      PadBytes = abPadded
  
  End Function
  
    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, Source As Byte, ByVal Length As Long)
  </code></pre>
  
  <p>Please show me the right way.</p>