Why the 'ICryptoTransform.TransformFinalBlock' method returns an array
larger than the .OutputBlockSize property states? As a result I'm getting
discrepancy when encrypting-decrypting.
Is this an undocumented feature, or I'm doing something wrong way:
...
Private mCryptor As ICryptoTransform
Private mDesCSP As New DESCryptoServiceProvider()
Private mIV() As Byte
...
Public Function Encrypt(ByVal bytesin() As Byte, _
ByRef bytesout() As Byte, _
ByVal byteskey() As Byte, _
ByRef bytesiv() As Byte) As Integer
'
mCryptor = mDesCSP.CreateEncryptor(byteskey, mIV)
Return MyCrypt(bytesin, bytesout)
End Function
...
Public Function Decrypt(ByVal bytesin() As Byte, _
ByRef bytesout() As Byte, _
ByVal byteskey() As Byte, _
ByRef bytesiv() As Byte) As Integer
'
mCryptor = mDesCSP.CreateDecryptor(byteskey, mIV)
Return MyCrypt(bytesin, bytesout)
End Function
...
Private Function MyCrypt(ByVal bytesin() As Byte, _
ByRef bytesout() As Byte) As Integer
'
Dim stat As Integer
Dim bIn() As Byte
Dim bOut() As Byte
'
bIn = bytesin '16 bytes
Console.WriteLine("Out block size: ",
mCryptor.OutputBlockSize.ToString) '8 bytes
'
' This always returns 8 bytes larger arr.than the input (24 bytes)
bOut = mCryptor.TransformFinalBlock(bIn, 0, bIn.GetLength(0))
bytesout = bOut
Return 0
End Function
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.