System.Security.Cryptography CF / OpenNetCF des.mode

N

Nickneem

I'm writing a console app which encrypts a key and I want to crosscheck
this key on my CF application.
Since the CF doensn't have the System.Security.Cryptography namespace I
used the opennet variant but a few things I can't figure out.

I can't set des.mode to ecb (can't set it to anything in the opennet
namespace).

If I use the functions below, the keys which are generated differ
totally from each other..

'Desktop version
Public Shared Function EncryptTripleDES(ByVal sIn As String, ByVal
sKey As String) As Byte()
Dim DES As New
System.Security.Cryptography.TripleDESCryptoServiceProvider
Dim hashMD5 As New
System.Security.Cryptography.MD5CryptoServiceProvider
Try
' scramble the key
sKey = ScrambleKey(sKey)
' Compute the MD5 hash.
DES.Key =
hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
' Set the cipher mode.
DES.Mode = System.Security.Cryptography.CipherMode.ECB
' Create the encryptor.
Dim DESEncrypt As
System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor()
' Get a byte array of the string.
Dim Buffer As Byte() =
System.Text.ASCIIEncoding.ASCII.GetBytes(sIn)
Return DESEncrypt.TransformFinalBlock(Buffer, 0,
Buffer.Length)
Catch ex As Exception
End Try
End Function

'Compact framework OPENNET version
Public Shared Function EncryptTripleDES(ByVal sIn As String, ByVal
sKey As String) As Byte()
Dim DES As New
OpenNETCF.Security.Cryptography.TripleDESCryptoServiceProvider
Dim hashMD5 As New
OpenNETCF.Security.Cryptography.MD5CryptoServiceProvider
Try
' scramble the key
sKey = ScrambleKey(sKey)
' Compute the MD5 hash.
DES.Key =
hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))

'' Get a byte array of the string.
Dim Buffer As Byte() =
System.Text.ASCIIEncoding.ASCII.GetBytes(sIn)
Buffer = DES.EncryptValue(Buffer)
Return Buffer
Catch ex As Exception
End Try
End Function

Thanks in advance,

Michael
 
V

Valery Pryamikov

Hi,
I only briefly looked over your code... and may be I misunderstood your
question...
but dmd5 hash is md5 hash no matter where it is implemented... and if you
get different results from calculation of md5 hash means that you are
hashing different data.

-Valery.
http://www.harper.no/valery
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top