this post was submitted on 11 Apr 2025
217 points (95.8% liked)

Programmer Humor

22354 readers
2832 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 2 days ago

I know it because I've actually implemented RSA as an exercise and know how it works.

What you're talking about with hashes is an implementation detail. It's an important one, because using exactly the same algorithm for signing and encryption has some security pitfalls, and it will usually be slower. However, the function you call is exactly the same. The hash is encrypted with the private key. It can be verified by generating the same hash, decrypting with the public key, and matching the two hashes.

See also: https://cryptobook.nakov.com/digital-signatures/rsa-signatures

Signing a message msg with the private key exponent d:

  • Calculate the message hash: h = hash(msg)
  • Encrypt h to calculate the signature: s = h^d^ (mod n)

The operation "h^d^ (mod n)" is just RSA encryption, but with the private key.