[Mono-dev] DES problem

Sebastien Pouliot sebastien.pouliot at gmail.com
Fri May 12 08:04:22 EDT 2006


Hello,

On Fri, 2006-05-12 at 11:36 +0200, Arnhoffer Károly wrote:
> Hi,
> 
> I've got a service application which uses encrypted data over network.
> My decrypting function gives different results with the same inputs on
> Mono which does not occour on .NET. The other mighty thing is that
> when I grab this function out of the service and test it in itself
> this problem does not happen again. What is wrong here?

Difficult to say. Your code sample, beside being in VB.NET ;-), is
incomplete. It only show the decryption process (the problem may be on
the encryption side) and doesn't show how you create the
ICryptoTransform (encryptor and decryptor) instances.

Please fill a bug into bugzilla with a complete sample and state the
version of the MS Fx that works and the version of Mono that doesn't.

> My function looks as follows (test version):
> 
>     Friend Function DecryptDataDES(ByVal tbytaData As Byte(), ByVal tbytaDESKey As Byte(), ByVal tbytaDESIV As Byte(), ByRef tbytaDecryptedData As Byte()) As Boolean
>         Dim lobjMemStream As MemoryStream
>         Dim lobjCryptoStream As CryptoStream
>         Dim lbytaDESKey As Byte()
>         Dim lbytaDESIV As Byte()
>         Try
>             'console.writeline()
>             ReDim lbytaDESKey(tbytaDESKey.Length - 1)
>             ReDim lbytaDESIV(tbytaDESIV.Length - 1)
>             tbytaDESKey.CopyTo(lbytaDESKey, 0)
>             tbytaDESIV.CopyTo(lbytaDESIV, 0)
> 
>             Console.WriteLine("tbytaData: " & Convert.ToBase64String(tbytaData))
>             Console.WriteLine("lbytaDESKey: " & Convert.ToBase64String(lbytaDESKey))
>             Console.WriteLine("lbytaDESIV: " & Convert.ToBase64String(lbytaDESIV))
> 
>             'teszt
>             If Not InitTripleDESCSP(lbytaDESKey, lbytaDESIV) Then
>                 'ak20050721: ha nem kényszerítjük ki az újrainicializálást, akkor linux/mono-n ugyanolyan bemenet mellett eltérő eredményt fog
>                 'adni a DecryptDataDES függvény. Emiatt InitTripleDESCSP(lbytaDESKey, lbytaDESIV) helyett InitTripleDESCSP(lbytaDESKey, lbytaDESIV, True)
>                 'szerepel a hívásban
>                 'console.writeline("Forced reinit...")
>                 'If Not InitTripleDESCSP(lbytaDESKey, lbytaDESIV, True) Then
>                 'mobjApp.Errors.Add(mstrResName, CommErrEnum.CantDecryptDataDES, , , "InitTripleDESCSP").Raise()
>                 Console.WriteLine("InitTripleDESCSP failed")
>             End If
> 
>             Console.WriteLine("lbytaDESKey: " & Convert.ToBase64String(lbytaDESKey))
>             Console.WriteLine("lbytaDESIV: " & Convert.ToBase64String(lbytaDESIV))
> 
>             lobjMemStream = New MemoryStream()
>             lobjCryptoStream = New CryptoStream(lobjMemStream, mobjDecryptTransform, CryptoStreamMode.Write)
>             'Írás közben dekódolja az adatot
>             lobjCryptoStream.Write(tbytaData, 0, tbytaData.Length)
>             lobjCryptoStream.FlushFinalBlock()
>             lobjCryptoStream.Close()    'e nélkül nem működik!!!
>             'Kiolvassuk a dekódolt adatot
>             tbytaDecryptedData = lobjMemStream.ToArray()
> 
>             Console.WriteLine("tbytaDecryptedData: " & Convert.ToBase64String(tbytaDecryptedData))
> 
>             Return True
>         Catch ex As Exception
>             Console.WriteLine("DecryptDataDES failed")
>         Finally
>             Try
>                 If Not lobjMemStream Is Nothing Then lobjMemStream.Close()
>                 If Not lobjCryptoStream Is Nothing Then lobjCryptoStream.Close()
>             Catch
>             End Try
>         End Try
>     End Function
> 
> Thanks!
> 
> Károly
> _______________________________________________
> 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