[Mono-dev] DES problem
Arnhoffer Károly
karnhoffer at ecron.hu
Fri May 12 05:36:11 EDT 2006
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?
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
More information about the Mono-devel-list
mailing list