Sign and encrypt with a public key

Sign and verify with RSA (PKCS#1 v1.5, PSS), ECDSA or Ed25519, and encrypt and decrypt with RSA (OAEP, PKCS#1 v1.5).

loading Sign and encrypt with a public key
About this tool

What does signing and encrypting with a key pair mean?

A key pair can do two different jobs, and people often mix them up. Signing proves who wrote something and that it was not changed: the owner signs with the private key, and anyone with the public key can check it. Encrypting hides something: anyone with the public key can lock a message, and only the private key opens it.

This page does both in your browser, with keys in PEM or OpenSSH format. For signing and verifying it supports RSA (PKCS#1 v1.5 and PSS), ECDSA (P-256, P-384, P-521) and Ed25519. For encrypting and decrypting it supports RSA only, with OAEP or the older PKCS#1 v1.5. Ed25519 and ECDSA keys only sign; that is how those algorithms are designed, not a limit of the page. The results match OpenSSL, so you can sign here and verify with openssl dgst, or the other way around.

It is useful for testing an integration, learning how signatures work, reproducing a bug in a signing service, or checking a signature someone sent you. The details follow the standards, for example RSA in RFC 8017. It is not a replacement for a proper tool when you protect real data: RSA encryption only handles short messages, which is why real systems encrypt data with a symmetric key and use RSA only to protect that key.

Keys and messages stay in the page. The sample pairs are made here and disappear when you close it.

How to sign, verify, encrypt or decrypt

  1. Choose What to do: Sign, Verify, Encrypt or Decrypt.
  2. Under Test key pair: pick a type and press Make a new test key pair, or paste your own key in Private key (PEM or OpenSSH): or Public key (PEM or OpenSSH line; a private key also works):. If the key is encrypted, fill in Passphrase of the key (if it is encrypted):.
  3. Type the Message (text):.
  4. Adjust the options that apply to the key: Hash:, RSA signature scheme:, PSS salt (bytes):, ECDSA signature format: or RSA encryption scheme:. Choose Base64 or hex in Signature and ciphertext as:.
  5. Read the Result, and use Copy result.
  6. To verify, paste the text in Signature to check:. To decrypt, paste it in Ciphertext to decrypt:. The buttons Check this signature and Decrypt this carry the result over for you.

Examples

Sign here, verify with OpenSSL

Pick RSA, sign a message with SHA-256 and PKCS#1 v1.5, and choose Base64. Decode the Base64 to a binary file, then check it with openssl dgst -sha256 -verify pub.pem -signature sig.bin message.txt. PKCS#1 v1.5 signatures are deterministic, so the same key, message and hash always give the same bytes.

Why a PSS signature changes each time

PSS adds random salt, so signing the same message twice gives two different valid signatures. On verification the salt length must match: a PSS signature made with a 32-byte salt fails if you verify with another length. Choosing PKCS#1 when the signature is PSS also fails.

An ECDSA signature for a JWT

Signature format DER (OpenSSL) is what OpenSSL writes. Raw r + s (JWT, WebCrypto) is the fixed-size form that JWT and the browser use. The numbers are the same, only the wrapping differs. To read a token, see the JWT decoder.

How much RSA can encrypt

A 2048-bit key with OAEP and SHA-256 takes at most 190 bytes; with PKCS#1 v1.5 the limit is 245 bytes. The page shows the limit for your key and refuses longer messages.

Common mistakes

  • "This needs a private key, and the one pasted has only the public part." Signing and decrypting need the private key.
  • "Encryption and decryption here work with RSA keys. Ed25519 and ECDSA only sign." Make or paste an RSA key.
  • "The message has N bytes but this key and scheme take at most M." Use a bigger key, a shorter message, or encrypt the data with a symmetric key.
  • "The ciphertext has N bytes; for this key it must have exactly M." The text is cut, or it came from another key.
  • "Could not decrypt. The key, the scheme (OAEP or PKCS#1) or the hash is not the one used to encrypt." Match the scheme and the OAEP hash with the sender.
  • "The text is not valid Base64." Check the Signature and ciphertext as option: the text may be hex.
  • Invalid signature. The message, the signature, the key or the settings do not match. Even one extra newline in the message changes the result.

Frequently asked questions

Is a valid signature proof of who sent it?

It proves that whoever has the private key signed this exact text. It does not say who that person is: you must know, by another route, that the public key belongs to them. A fingerprint is the usual way to compare.

Should I use OAEP or PKCS#1 v1.5 for encryption?

Use OAEP. The old PKCS#1 v1.5 encryption has known weaknesses and is only here to interoperate with old systems.

Can I use my SSH key?

Yes, OpenSSH keys are read, with their passphrase if they have one. For creating a pair, see the SSH key generator.

Why does Ed25519 not ask for a hash?

Ed25519 hashes the message internally, as part of the algorithm, so there is no hash to choose.

Equivalent commands

# Sign with RSA, SHA-256, PKCS#1 v1.5
openssl dgst -sha256 -sign key.pem -out sig.bin message.txt

# Verify
openssl dgst -sha256 -verify pub.pem -signature sig.bin message.txt

# Encrypt with RSA OAEP, SHA-256
openssl pkeyutl -encrypt -pubin -inkey pub.pem \
  -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 \
  -in message.txt -out cipher.bin
Report a problem