0

When I perform following action in terminal I get different decryption text compared to message showing that these keys map to unique cipher

openssl enc -des-ecb -in text.in -out cipher.txt -k '96508092'
openssl enc -d -des-ecb -in cipher.txt -out text.in -k '82514145'

But when I implement it in programming using <openssl/des.h>, Crypto.cipher, pyDes I got same decrypted text. I found why I get same text and it is because these 8 byte keys map to a unique 7 byte key 0x3832343134313401. Refer to my previous question Why can I encrypt data with one DES key and successfully decrypt with another?

My question is: how is it implemented on OpenSSL terminal commands differently compared to mentioned libraries that it could map these 8 byte keys to unique cipher?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
ceasif
  • 345
  • 2
  • 14

1 Answers1

0

You need to use an uppercase -K if you want to supply key bytes. Otherwise, OpenSSL assumes its a password and derives a (different) key from it.

You also need to use the hex versions of the keys:

openssl enc -des-ecb -in text.in -out cipher.txt -K '3832353134313435'
openssl enc -d -des-ecb -in cipher.txt -out text.out -K '3933353035303434'
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • @ceasif Did you use the hex versions of the keys (see final paragraph)? The example I showed above worked perfectly for me. – Duncan Jones Apr 23 '14 at 15:18
  • So how does openssl works with key as it is taking taking any size of key. What is the procedure to go to actual key here .. openssl enc -d -des-ecb -in cipher.txt -out text.out -K '393335303530343412345123345677812345678812324' – ceasif Apr 23 '14 at 15:28
  • @ceasif Not sure, I'm no OpenSSL expert. I'd guess it uses the first N bytes (where N is the required key length). – Duncan Jones Apr 23 '14 at 15:43
  • Thank you for sorting out. I will be glad to have your help in this quest http://stackoverflow.com/questions/23249256/openssl-is-acting-open-to-any-size-key – ceasif Apr 23 '14 at 15:44