3DES confusion

T

tshad

I am trying to use 3DES to encrypt my keys and am using VS 2003.

I am confused with some code I have that seems to use a hash (MD5) in the
3DES. But a Hash is one way. You are not suppose to be able to decrypt it.
The only thing I can figure is that it is using the hash only on the key.

Also, the

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

The other thing I noticed was that when I looked at the value pdb.HashName
and des.pdb.HashName it shows "SHA1" instead of "MD5"????

Am I doing something wrong here?

Thanks,

Tom
 
M

Mark Rae

I am trying to use 3DES to encrypt my keys and am using VS 2003.

I am confused with some code I have that seems to use a hash (MD5) in the
3DES. But a Hash is one way. You are not suppose to be able to decrypt
it. The only thing I can figure is that it is using the hash only on the
key.

Contact me privately and I'll give you a copy of my 3DES encryption base
class - it's in C#, but should give you enough guidance to solve your
problem...
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top