Search code examples
cvb.netencryptiondes3des

VB Unable to retrieve string after 3DES encryption


Initial conditions:

Private TheKey() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
Private Vector() As Byte = {&H7C, &H22, &H2F, &HB2, &H92, &H7D, &H82, &H8A}

I then proceed to encrypt the string: "asd" (without quotations) using:

CryptoStream(ms, des.CreateEncryptor(TheKey, Vector), CryptoStreamMode.Write)

input: asd
output: 82804AD2B295E9E3

When i try to encrypt the same string with the same key/vector on http://tripledes.online-domain-tools.com/ as shown below (can't post image due to reputation):

online 3DES encryption

I get a different result.

My ultimate goal is to have this output decrypted in a C application. But two 3DES encryptors giving 2 different results is a show stopper.. Any thoughts about what could be causing this ?

Thanks in advance!


Solution

  • A good idea to test your crypto against some other "oracle". But two issues apparent with your use of the online tool:

    • the key should be given as hex not text (the VB code has a byte array). Presumably 0102030405060708
    • 3DES is the algorithm, but the VB code uses classic DES - there's a separate TripleDESCryptoServiceProvider for 3DES

    However that site gives me the same encrypted text for both DES and 3DES, so it may not be a reliable oracle anyway? Try another, but may need to use a plain text key (first two I looked at didn't offer hex input in any obvious way)