Openssl command line for RC4 encryption, not expected result, don't understand

This is probably a stupid question, but I can't figure it out. I am currently using this website: http://www.fyneworks.com/encryption/rc4-encryption/ for rc4 encryption to prove the concept. For example, I entered β€œa” as plaintext, β€œa” as a password, and I get β€œ71” as ciphertext (this is the ascii representation of β€œq”). I wanted to do the same from the command line using openssl:

> echo a | openssl rc4 -nosalt -out /tmp/uuu enter rc4 encryption password: Verifying - enter rc4 encryption password: > cat /tmp/uuu | xxd 0000000: 5896 X. 

So, we get '5896' instead of '71', and that is what I do not understand. If someone could explain to me, I would be grateful.

Thanks!

+4
source share
2 answers

Thanks to a friend, we found out what happened. He told me to type a key

 echo -ne "a" | openssl rc4 -pass pass:a -e -nopad -nosalt -p key=0CC175B9C0F1B6A831C399E269772661 

We see that the addition is added, with 0x61 we entered at the end. It turns out openssl generates a key from the pass.

Instead, if we directly enter the key with the -K option:

 echo -ne "a" | openssl rc4 -K 61 -e -nopad -nosalt -p key=61000000000000000000000000000000 

We see that there is an addition with '0'. In general, he does not want us to use a key that is too small (since for rc4 the key must be at least 40 bits long). Now try the 128b key:

 echo -ne "foobar" | openssl rc4 -K "6162636465666768696A6B6C6D6E6F70" -e -nopad -nosalt | xxd 0000000: caaf 2cbf d334 ..,..4 

The result is the same as on the web page :)

+4
source

Work in progress

Here is an interesting sample for you. Using "0" as the encryption key, we get some strong trends between plaintext and ciphertext. See below.

What interests me in the difference between the two implementations is that fyne is growing monotonously, while OpenSSL is a bit of a ladder. I will look at this again later. I mark this community wiki as I don’t find this answer yet, but I decided that analysis could help.

Fine:

 0(0) = B8 0(1) = B9 0(2) = BA 0(3) = BB 0(4) = BC 0(5) = BD 0(6) = BE 0(7) = BF 0(8) = B0 0(9) = B1 

OpenSSL:

 0(0) = 72 0(1) = 73 0(2) = 70 0(3) = 71 0(4) = 76 0(5) = 77 0(6) = 74 0(7) = 75 0(8) = 7A 0(9) = 7B 

Commands Used

 cat -n N > /tmp/test #Where n is a number openssl rc4 -e -nosalt -in /tmp/test -out /tmp/uuu cat /tmp/uuu |xxd 
0
source

Source: https://habr.com/ru/post/1384227/


All Articles