T
tshad
I am trying to use 3DES to encrypt my keys and am using VS 2003.
I am trying to pass a value like: mCJ4@L2= where the value is 8 bytes long.
I was told that you need a 16 byte key. But this seems to be working. I
don't want to change it if I don't have to as I already have encrypted some
of my data.
I pass it in the line:
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,New Byte(-1)
{})
I don't get an error but I want to make sure this isn't going to cause me a
problem later.
*****************************************************
Public Shared Function TripleDESEncode(ByVal value As String, ByVal
key As String) As String
Dim des As New
Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,
New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("TripleDES", "MD5", 168, New
Byte(7) {})
Dim ms As New IO.MemoryStream((value.Length * 2) - 1)
Dim encStream As New Security.Cryptography.CryptoStream(ms,
des.CreateEncryptor(), Security.Cryptography.CryptoStreamMode.Write)
Dim plainBytes As Byte() = Text.Encoding.UTF8.GetBytes(value)
encStream.Write(plainBytes, 0, plainBytes.Length)
encStream.FlushFinalBlock()
Dim encryptedBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(encryptedBytes, 0, CInt(ms.Length))
encStream.Close()
Return Convert.ToBase64String(encryptedBytes)
End Function
*************************************************************
Thanks,
Tom
I am trying to pass a value like: mCJ4@L2= where the value is 8 bytes long.
I was told that you need a 16 byte key. But this seems to be working. I
don't want to change it if I don't have to as I already have encrypted some
of my data.
I pass it in the line:
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,New Byte(-1)
{})
I don't get an error but I want to make sure this isn't going to cause me a
problem later.
*****************************************************
Public Shared Function TripleDESEncode(ByVal value As String, ByVal
key As String) As String
Dim des As New
Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,
New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("TripleDES", "MD5", 168, New
Byte(7) {})
Dim ms As New IO.MemoryStream((value.Length * 2) - 1)
Dim encStream As New Security.Cryptography.CryptoStream(ms,
des.CreateEncryptor(), Security.Cryptography.CryptoStreamMode.Write)
Dim plainBytes As Byte() = Text.Encoding.UTF8.GetBytes(value)
encStream.Write(plainBytes, 0, plainBytes.Length)
encStream.FlushFinalBlock()
Dim encryptedBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(encryptedBytes, 0, CInt(ms.Length))
encStream.Close()
Return Convert.ToBase64String(encryptedBytes)
End Function
*************************************************************
Thanks,
Tom