Looking for a Triple DES implementation

David Kramer david-8uUts6sDVDvs2Lz0fTdYFQ at public.gmane.org
Thu Jun 14 01:20:13 EDT 2007


Derek Atkins wrote:
> Have you tried OpenSSL?

Huh?  Please explain.

> Also, what MODE are you using?  CFB?  CBC?

ECB

> What are you doing about the Initialization Vector?
You mean the key?  Yes, I know the phrase he's using as a key, and am
using the same thing.

> There are lots of reasons that two encryptions of the same plaintext
> wont result in the same ciphertext.  The question is whether the
> ciphertext can be converted back to the correct plaintext.

In this case, the question is can I generate the same exact output as
him, because the program that reads it expects what his program is
putting out.

I took a closer look at his program, and he's converting the output to
Base64, which explains why his output is printable characters.  He
didn't tell me that.  He's also treating the input as UTF8, but I don't
know if that matters when the input is straigh old typewriter characters.

This is the guts of his C# program:
public static string EncryptKey(string inputString, string encryptionKey)
       {
           //Used encrypt/decrypt examples from
http://www.codeproject.com/useritems/Cryptography.asp

           byte[] keyArray;
           byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(inputString);

           keyArray = UTF8Encoding.UTF8.GetBytes(securityKey);

           TripleDESCryptoServiceProvider tdes = new
TripleDESCryptoServiceProvider();
           tdes.Key = keyArray;
           tdes.Mode = CipherMode.ECB;
           tdes.Padding = PaddingMode.PKCS7;

           ICryptoTransform cTransform = tdes.CreateEncryptor();
           byte[] resultArray =
cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
           tdes.Clear();
           return Convert.ToBase64String(resultArray, 0,
resultArray.Length);
       }

Thanks.





-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.






More information about the Discuss mailing list