- Based on https://gist.github.com/cevaris/e003cdeac4499d225f06
- updated for Python 3.
- One script to generate a signature for an arbitrary input message.
- One script to validate the signature using only the private key.
You'll need Python 3 and to pip install -r requirements.txt
.
Then, set up private and public keys with:
$ bash generate_key.sh
Generating RSA private key, 1024 bit long modulus
...++++++
..++++++
e is 65537 (0x10001)
$ python 0_export_public_key.py
(done)
$ cat public_key.txt
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDU4d3jauQxxI1TmID8q4ejPlMb
1bqYC3GHqnVyJI+TUi84kasfpu3wUbmEhLXwdlSx+w56X6IP2YRhBaYJ7GnI/D2S
dpYh61khiKNaggkrh7d2Z2I1lrtyw0I1209ruKRevKIkvpNKaAVhCYJnBYPOdgJK
2Hg/BGFYnKljSW5GDwIDAetc
-----END PUBLIC KEY-----
Next, create a signature for an arbitrary input message:
$ python 1_sign.py
message? Hello there
Signature:
6970bbd7c1a1a140fa...............................
Then validate the signature matches for the given input, using only the public key:
$ python 2_verify.py
Message? Hello there
Signature? 6970bbd7c1a1a140fa24bd65a658ca.........................
Successfully verified message
Validate that a different message with same signature fails:
$ python 2_verify.py
Message? Foobar
Signature? 6970bbd7c1a1a140fa24bd65a658ca.........................
FAILED