Exercises: RSA Sign / Verify

In this exercise we shall sign messages and verify signatures using the PKCS#1 v.1.5 RSA signature algorithm with 4096-bit keys, following the technical specification from RFC 8017, using SHA3-512 for hashing the input message. The RSA-PKCS1 v1.5 digital signature algorithm can be found as library for the most programming languages.

The RSA private key will be given encoded in PEM format (RFC 7468, see the example). The corresponding RSA public key will also be given encoded in PEM format. The RSA signature is 4096-bit integer (1024 hex digits).

Sign a Message with RSA

Write a program to sign given text message with given 4096-bit private key, using the PKCS#1 v.1.5 RSA signature algorithm with SHA3-512 hashing for the input message. The input consists of 2 text lines. The first line holds the input message for signing. The next few lines holds the private key as hex string. Print the output as JSON document, holding the input message + the public key of the signer (as hex string) + the RSA digital signature (as hex string).

Verify Message Signature with RSA

Write a program to verify RSA signature (calculated by using PKCS#1 v.1.5 + SHA3-512), created by the previous exercise. The input comes as signed message (first line) + RSA digital signature (second line) + 4096-bit RSA public key (all input lines to the end). Print as output a single word: "valid' or "invalid".