- 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
generate keypair openssl from terminal macos
private key:
_openssl genpkey -algorithm RSA -out prod_vtb_private_key.pem -pkeyopt rsa_keygen_bits:2048_
public key: for only extract public key from the existing private key:
_openssl pkey -in prod_vtb_private_key.pem -pubout -out prod_public_key.pem_
for generate public key with more infomation confirm:
_openssl req -new -x509 -sha256 -key prod_vtb_private_key.pem -out prod_publickey_key.cer_
this command require some information:
Country Name (2 letter code): E.g., US
State or Province Name (full name): E.g., California
Locality Name (eg, city): E.g., San Francisco
Organization Name (eg, company): E.g., My Company Ltd
Organizational Unit Name (eg, section): E.g., IT Department
Common Name (e.g. server FQDN or YOUR name): This is important. Use the domain name (like www.example.com), server name, or identifier the certificate is for. For local testing, localhost is often used.
Email Address: Optional.