1

I'm trying to test the interoperability of openssl when used in Ruby on one side, and on the command line on the other side.

I generated a RSA certificate and extracted its public key this way:

openssl req -x509 -nodes -days 1825 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
openssl rsa -in mycert.pem -pubout > mycert.pub

I wrote a Ruby script that does 2 things:

  1. it encodes/decodes a test file with the public key first and then with the private key (using Base64 encoding on top of the RSA encoding to make network communication easier)
  2. it runs system commands to encrypt the same test file with the openssl command line tool

You can find the code of this Ruby script in the following Gist: https://gist.github.com/dirtyhenry/4673331 (cf. the poc-openssl-rsa.rb file)

My question is: how come my Ruby-generated public-encrypted.txt file is different from the public-encrypted-cl64.txt? Is it caused by some file-system side effects? (ie. one is a string when the other is a file or something?)

Thanks.

1 Answer 1

2

I've found out that the two are indeed interoperable. It's just that paddings bring some randomness which leads to the fact that 2 successive encodings will result in 2 different encoded data.

cf. http://en.wikipedia.org/wiki/RSA_%28algorithm%29#Padding_schemes :

practical RSA implementations typically embed some form of structured, randomized padding into the value m before encrypting it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.