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
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