Using RSA to Exchange Cryptographic Keys

From the original Xaede archive. This is historical writing, preserved in a new reading edition. Technical advice, tools and project status reflect the time of publication.

The following is a methodology for programmers to provide a simplified implementation for using the RSA algorithm to exchange a shared private key from another cryptosystem such as AES or Blowfish for further secure communications. This methodology will be described following the typical practice in cryptography as an imaginary conversation between two fictional characters that have names taken from successive letters of the alphabet. For the the following discussion, Alfred represents an entity wishing to instantiate secure communications, and Beatrice is representative of the recipient.

To begin, Alfred has already obtained in a secure fashion a copy of Beatrice’s public RSA key, e.g. she handed him a disk with the key, or he verified it with a hashing algorithm, or he used a trusted 3rd-party mechanism, etc. Alfred begins his conversation with Beatrice by generating his own RSA key with an arbitrary number of bits (though hopefully as least as large as Beatrice’s). Additionally, Alfred should pick a key length that is of sufficient length as to be thought computationally impossible to guess it in a reasonable time frame, say a couple of centuries at least.

At this point, Alfred has a copy of Beatrice’s public RSA key, and Alfred has generated his own RSA key. Alfred then transmits his public key to Beatrice, which has been first encrypted with Beatrice’s public key, and then cryptographically signed with Alfred’s private key. This way, only Beatrice may be able to decrypt Alfred’s public key, and with Alfred’s private key signature, Beatrice can validate that she is indeed speaking to Alfred.

Upon receipt of Alfred’s message, Beatrice will then decrypt Alfred’s public key using her private key. She then will generate a new key that will be used as a private shared key for further communications. She takes her new key, and encrypts it with Alfred’s public RSA key. Beatrice then signs the result with her private key, and transmits the resulting message to Alfred. At this point, Beatrice has a cryptographically-signed message from Alfred, along with his public key, and the new shared private key generated by Beatrice.

Upon receipt of Beatrice’s response, Alfred uses his private key to decrypt the private shared key he received from Beatrice. He can further use Beatrice’s public key to validate her private-key signature of the message she sent. At this point, both Alfred and Beatrice have established each other’s cryptographic but not real identity, and have exchanged a key that they can use to safely encrypt any further messages they wish to exchange.

If Alfred and Beatrice want to eliminate any real possibility of cryptanalytic attack against their further communications, they may use the private shared key only to exchange a single message, and will generate a new shared key every time they wish to send each other a message.

So, how to we easily translate this into programmer-land? Here is a simple example: if you think of Alfred as a computer game client, and Beatrice as a computer game server, you now have a methodology that will allow you to prevent 3rd-parties from listening in on any sensitive communications, e.g. paying a monthly subscription fee, transmission of critical or advertisement material, purchasing merchandise from inside a game, etc.