Public-Key Cryptography and Digital Signatures: Private Keys, Public Keys, ECDSA and Signing a Transaction

Blockchain Developer 50 min min read Updated: Nov 17, 2026 Beginner
Public-Key Cryptography and Digital Signatures: Private Keys, Public Keys, ECDSA and Signing a Transaction
Beginner Topic 2 of 3

Two Kinds of Keys

SymmetricAsymmetric (public-key)
KeysOne shared secret keyA pair: private key and public key
UseFast encryption of dataIdentity, signatures, key exchange
ProblemHow to share the key safely?Solved: the public key can be shared openly

The Key Pair

  • Private key: a secret random number. Only you know it. It controls your funds
  • Public key: calculated from the private key. Safe to share
  • You can go from private to public easily, but not back
  • Blockchains use elliptic curve cryptography, for example secp256k1 in Bitcoin and Ethereum

Mailbox Example

Your public key is like your mailbox address and slot: anyone can drop a letter. Your private key is the key that opens the mailbox. Whoever has the private key owns what is inside.

Digital Signature

A digital signature proves that the owner of the private key approved a message and that the message was not changed.

  1. Asha writes: 'Send 2 coins to Ravi'
  2. She signs it with her private key, which produces a signature
  3. Anyone can verify it with her public key
  4. If the message changes by even one letter, verification fails
text message + private key --sign--> signature message + signature + public key --verify--> true or false

Python Example

Install the library first with pip install ecdsa.

python from ecdsa import SigningKey, SECP256k1, BadSignatureError private_key = SigningKey.generate(curve=SECP256k1) public_key = private_key.get_verifying_key() message = b"Send 2 coins to Ravi" signature = private_key.sign(message) print("valid:", public_key.verify(signature, message)) try: public_key.verify(signature, b"Send 200 coins to Ravi") except BadSignatureError: print("tampered message rejected")
Result

valid: True tampered message rejected

Why This Matters for Blockchain

  • Nodes accept a transaction only if the signature is valid
  • Nobody needs your password. They just check the math
  • Lose the private key = lose the funds. There is no reset button

Practice

  1. Which key do you share and which do you keep secret?
  2. What happens if someone changes a signed message?
  3. Why can nobody help you recover a lost private key on a public chain?

Conclusion

Private keys sign, public keys verify. Digital signatures prove ownership and integrity without revealing secrets, and they are the core of blockchain transactions.

Quick Summary: key types; pair; mailbox; signature; Python; importance.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators