I want to use two key pairs to implement secure messaging with non-repudiation between two communicating systems. I have generated and stored two sets of key pairs using:
sys1_key = OpenSSL::PKey::RSA.generate( 2048 )
sys2_key = OpenSSL::PKey::RSA.generate( 2048 )
Both of these key pairs have had their separate public and private keys saved out to files:
- sys1.pub.pem
- sys1.priv.pem
- sys2.pub.pem
- sys2.priv.pem
System 1 has its own public and private keys as well as the public key of System 2. System 2 has its own public and private keys as well as the public key of System 1.
On System 1, I want to take the message "Hello world" and encrypt it using System 1's private key and System 2's public key. This message can only be decrypted by System 2 using its own private key and System 1's public key.
We currently effect a similar process using GPG but I want to automate the process -- any help appreciated. We're on Ruby 1.9.2.