Re: TransformFinalBlock returns

Tarik Soulami <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <FDA786C04E4A034989BB35DC0D41DD4403E595B2@red-msg-09.redmond.corp.microsoft.com>
This is because we use PKCS style padding, and we need to add a block of padding. So 24 bytes will yield 32 bytes of encrypted text. When this encrypted bytes will be decrypted, we will know how to remove the 8 bytes of padding and will return the original 24 bytes of plain text.

Thanks,
--Tarik

-----Original Message-----
From: Valentina Shkolnikov [mailto:[email protected]]
Sent: Friday, June 14, 2002 12:22 PM
To: [email protected]
Subject: [DOTNET] TransformFinalBlock returns


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.

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.