You're using OpenSSL incorrectly. The obsolete -k
parameter specifies a password, not a key file. This password (literally "key.txt" in this case) is then run through a key derivation function (PBKDF2, per your command line). However, if you're providing a key already, (as opposed to a password), you don't need (and shouldn't use) a slow key-derivation function. Since you are using a key as though it's a password in one case and actually using it as a key in the other, of course the output will be different. The ciphertext will differ, as it's created using a derived key (rather than one provided directly), plus KDFs require additional parameters (work factor and salt) which must be stored and transmitted in plain text as well.
Indeed, looking at the base64-decoded output of the openssl
command, it is relatively long (40 bytes) contains the plain English word "Salted", which is unexpected if it were nothing but ciphertext of English text:
$ echo -n 'U2FsdGVkX1/CxK/qRQDXLsl/pTE650K/xcHnPWbhb3Z1EtyrNPyzVA==' | base64 -d | hd
00000000 53 61 6c 74 65 64 5f 5f c2 c4 af ea 45 00 d7 2e |Salted__....E...|
00000010 c9 7f a5 31 3a e7 42 bf c5 c1 e7 3d 66 e1 6f 76 |...1:.B....=f.ov|
00000020 75 12 dc ab 34 fc b3 54 |u...4..T|
The website output also contains a handful of printable ASCII characters:
$ echo -n 'c9FxRbKYE/We1igMIU58833njnVjs6KH' | base64 -d | hd
00000000 73 d1 71 45 b2 98 13 f5 9e d6 28 0c 21 4e 7c f3 |s.qE......(.!N|.|
00000010 7d e7 8e 75 63 b3 a2 87 |}..uc...|
but no plain English words, and (as expected) a significantly shorter length (just 24 bytes, which makes sense if you take the 20-byte input string "hi all I am someone" and pad it out to a multiple of DES' 64-bit block size). I don't know exactly what the format of the OpenSSL command is, but that's definitely your problem.
You're also using the website you linked incorrectly. It expects the key in plain text, not base64 (or hex) encoded. Since your key contains non-printable characters, this is tricky to paste into the text box, but I tried it with a key made only from printable characters and it worked correctly.
To actually use the key you want with openssl
, you first need to convert it to a hex representation (there might be an easier way to do this on the command line but this uses tools most likely already installed):
$ echo -n "CiC4IOH/ASAHd7dxOSVIw4VSG/yG33FN" | base64 -d | od -A n -t x1 | tr -d '\n '
0a20b820e1ff01200777b771392548c385521bfc86df714d
You can then pass this hex-encoded key to the -K
(note: capital K) parameter in openssl enc
:
$ echo -n 'hi all I am someone' | openssl enc -des-ede3 -base64 -K 0a20b820e1ff01200777b771392548c385521bfc86df714d
Lv0OrqobWvh/u681nIe3ONhSy0PYnhlK
I can't find any way to pass the symmetric key directly to openssl
from a file, unfortunately. OpenSSL is a cryptographic library, more than a command-line tool; its command-line utilities are often convenient, but it's mostly used for its API.