# CRYPTOGRAPHY Cryptography is the science of protecting information using codes so that only the right people can read it. In blockchain, it helps keep transactions secure, private, and tamper proof # Types of Cryptography There are three main types of cryptography: --- ## 1. **Symmetric Key Cryptography** ### What it means: One **single key** is used to **encrypt** and **decrypt** the data ### How it works: * You use a secret key to lock (encrypt) a message * You use the same key to unlock (decrypt) it ### Use case: Used in private systems where both sender and receiver can safely share the secret key (e.g., AES encryption) * If someone steals the key they can access everything --- ## 2. **Asymmetric Key Cryptography** (Public-Key Cryptography) ### What it means: Uses two keys**: a public key (shared) and a **private key** (kept secret) ### How it works: * The **public key** is used to encrypt data * Only the matching private key can decrypt it * Also used for digital signatures ### Use case in blockchain: Used in wallets: * Your public key is your wallet address. * Your private key proves that you own it and can send funds. ### Advantage: More secure for communication no need to share your private key. --- ## 3. **Hash Functions** ### What it means: A hash function turns any input (text, number, file) into a fixed-length string of characters ### How it works: * You input: data it gives a unique output (called a hash) * It's one way: you can’t reverse it back to the original input ### Use case in blockchain: * Used in block creation mining (PoW) and data integrity * Example: Bitcoin uses SHA-256 hashing ### Key Feature: Even a small change in input gives a completely different hash ___ # Keys and Addresses in Blockchain In blockchain, keys and addresses are how users own, access, and transfer their crypto or data securely --- ## 1. **Private Key** * A secret code known only to you * It's like your password or signature * Used to sign transactions and prove ownership of crypto If someone gets your private key, they can steal your crypto --- ## 2. **Public Key** * Generated from the private key * Can be shared with anyone * Used to create your wallet address and verify your signature --- ## 3. **Wallet Address** * A short version of your public key * It’s like your account number on the blockchain * People can send you crypto using your wallet address --- | Term | Like in Real Life | | - | - | | Private Key | Your password or PIN | | Public Key | Your identity | | Address | Your account number | --- ### Example: * Private key: `5Jv3kYfZ...` (never share this) * Public key: `041a3b...` * Address: `0xAb12Cd34Ef...` (share this to receive crypto) --- ### Summary: * **Private key** = proves ownership, stay secret * **Public key** = created from private key * **Address** = short version to receive crypto ___ # What is VRS in Ethereum? * When someone sends a transaction in Ethereum, it is digitally signed using their private key * This signature is broken into three parts: V, R, and S. Together, they prove the transaction is authentic and was sent by the real owner. ## 1. R (Signature Component) * A 256-bit value from the signature. * It's part of the output from the ECDSA algorithm (the signing algorithm Ethereum uses). * It helps identify the curve point used in the signature. ## 2. S (Signature Component) * Also a 256-bit value. * It works with R to prove the signature is valid. * Helps ensure the transaction wasn’t tampered with. ## 3. V (Recovery ID / Chain ID Info) * Originally used to help recover the public key * Value is usually 27 or 28 (in older Ethereum) or chain-dependent in newer versions (EIP-155) * Now also helps protect against replay attacks (when a signed tx is reused on another chain) In Ethereum, the recipient of a payment is identified by an address, just like a bank account. This address can belong to a user (EOA) created from a public key or to a smart contract, which doesn't have a private key.