TransformFinalBlock returns

Valentina Shkolnikov <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <DOTNET%[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.