[Mono-dev] DES problem

Sebastien Pouliot sebastien.pouliot at gmail.com
Thu May 18 10:12:54 EDT 2006

Hello Arnhoffer,

Your code should *always* check for CanReuseTransform (and should also
check for CanTransformMultipleBlock if it's not using a CryptoStream)
and, if false, re-create the transform.

The reason is the .NET crypto classes are pluggable - so it's possible
that another implementation, or a future version of the FX, will change
those values. Checking those values will make your code resistant to
such changes and more adaptable to other algorithms or different

On Thu, 2006-05-18 at 13:28 +0200, Arnhoffer Károly wrote:
> Hi,
> There is a little difference between .NET and Mono. When I call the routine below in .NET I get the results:
> True
> True
> With Mono it says:
> False
> True.
> Is it possible to set this CanReuseTransform property to true and reuse the transform once again or shall I reinitialize it every time? (I found that with Mono I can not decrypt two or more times with the same ICryptoTransform. I get different results with same inputs.)
> The code snippet:
>     Private mobjEncryptTransform As ICryptoTransform
>     Private mobjDecryptTransform As ICryptoTransform
>     Private Function InitTripleDESCSP(ByVal tbytaDESKey As Byte(), ByVal tbytaDESIV As Byte(), Optional ByVal tlogForceInit As Boolean = False) As Boolean
>         Dim lobjTripleDESCSP As TripleDESCryptoServiceProvider
>         Try
>             If lobjTripleDESCSP Is Nothing OrElse mobjDecryptTransform Is Nothing OrElse mobjEncryptTransform Is Nothing OrElse tlogForceInit Then
>                 lobjTripleDESCSP = New TripleDESCryptoServiceProvider()
>                 mobjDecryptTransform = lobjTripleDESCSP.CreateDecryptor(tbytaDESKey, tbytaDESIV)
>                 mobjEncryptTransform = lobjTripleDESCSP.CreateEncryptor(tbytaDESKey, tbytaDESIV)
>                 Console.WriteLine(mobjDecryptTransform.CanReuseTransform)
>                 Console.WriteLine(mobjDecryptTransform.CanTransformMultipleBlocks)
>             End If
>             Return True
>         Catch ex As Exception
>         End Try
>     End Function
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
Sebastien Pouliot  <sebastien at ximian.com>
Blog: http://pages.infinit.net/ctech/

More information about the Mono-devel-list mailing list