pabit / KeyFactor

A very basic example in factoring tiny RSA public keys in order to generate a corresponding RSA private key.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

A very basic example in factoring tiny RSA public keys in order to generate a corresponding RSA private key.

Usage

  1. Generate a new RSA private key (With a tiny key size)

openssl genrsa -out private.rsa 96

  1. Extract the public key from the new private key (In PEM format so KeyFactor can read it)

openssl rsa -in private.rsa -out public.rsa -pubout -outform PEM

  1. Create a text file with the data to encrypt. We have to use a small plaintext due to the tiny key size, e.g. 96 bit keysize is a max of 12 bytes plaintext (96/8 = 12).

echo 0123456789! > plaintext.txt

  1. Encrypt the data with the public key so only the private key may decrypt it

openssl rsautl -in plaintext.txt -out ciphertext.txt -inkey public.rsa -pubin -raw

  1. Use the public key to create a new private key (About ~4 minutes for a 96 bit key)

ruby KeyFactor.rb -verbose -public public.rsa -private solved_private.rsa

  1. Decrypt the data with the newly found private key

openssl rsautl -decrypt -in ciphertext.txt -inkey solved_private.rsa -raw

License

The source code is available under the GPLv3 license, please see the included file gpl-3.0.txt for details.

About

A very basic example in factoring tiny RSA public keys in order to generate a corresponding RSA private key.


Languages

Language:Ruby 100.0%