Kernel of Truth

Category: Cryptography

  • Cryptography Essentials

    🔐 Symmetric vs Asymmetric Encryption

    FeatureSymmetric EncryptionAsymmetric Encryption
    🔑 Key UsageSame key for encryption and decryptionPublic key to encrypt, private key to decrypt
    👥 Parties InvolvedRequires both parties to share the same keyUses a key pair: public (shared), private (kept secret)
    SpeedFast and efficientSlower due to complex mathematics
    🔄 Common Use CasesEncrypting files, VPNs, full disk encryptionSecure email, SSL/TLS, digital signatures
    📦 ExamplesAES, DES, BlowfishRSA, ECC, DSA

    🔐 Symmetric Encryption – Quick Overview

    • How it works:
      One secret key is used for both encrypting and decrypting the message.
    • Challenge:
      Securely sharing that key between sender and receiver.
    • Analogy:
      Like a shared safe key—if both people have it, they can lock/unlock the box.

    Fast for large volumes of data
    Risky if the key is intercepted


    🔐 Asymmetric Encryption – Quick Overview

    • How it works:
      Each party has a key pair: a public key (shared with anyone) and a private key (kept secret).
      What one key encrypts, the other can decrypt.
    • Challenge:
      Slower performance, but safer for exchanging secrets initially.
    • Analogy:
      Like sending a message in a lockbox with an open padlock—only the owner has the key to open it.

    ✅ Enables secure key exchange and digital signatures
    Slower for bulk data


    🔄 Hybrid Approach (TLS Example)

    Modern systems (like HTTPS/TLS) use both:

    1. Asymmetric encryption to exchange a symmetric session key securely.
    2. Symmetric encryption for the rest of the session (for speed).

    🧠 Summary

    TaskBest Method
    Encrypt large filesSymmetric (AES)
    Exchange keys securelyAsymmetric (RSA, ECC)
    Digital signaturesAsymmetric (RSA/DSA)
    Secure session (TLS)Hybrid (Asymmetric + Symmetric)

    🔐 Symmetric is fast. Asymmetric is smart. Together—they’re secure.

    🔐 Digital Certificates & Public Key Infrastructure (PKI) Explained

    In today’s digital world, trust is everything. Whether it’s a secure website, encrypted email, or authenticated software, Digital Certificates and PKI make it possible to verify identities and protect sensitive data online.


    📄 What Is a Digital Certificate?

    A digital certificate is like an online passport — it binds a public key to the identity of a person, system, or organisation, and confirms that the key belongs to them.

    🔍 Contains:

    • Public Key
    • Owner’s identity (domain, email, organisation name)
    • Issuer information (Certificate Authority or CA)
    • Expiry date
    • Digital Signature from the CA

    🧾 Common Formats:

    • .crt, .pem, .cer — for websites
    • .pfx, .p12 — includes private key for client certs
    • .csr — certificate signing request

    🏛️ What Is PKI (Public Key Infrastructure)?

    PKI is the system that manages keys and certificates. It defines the roles, policies, hardware, and software used to issue, store, revoke, and manage digital certificates.

    🔧 Core Components:

    ComponentRole
    Certificate Authority (CA)Issues and signs digital certificates
    Registration Authority (RA)Verifies identity before certs are issued
    Public & Private KeysAsymmetric encryption for authentication and encryption
    CRL/OCSPCheck if a certificate has been revoked
    Certificate StoreSecure local storage for trusted certs

    🔐 How It Works

    1. Key Pair Generation
      A public/private key pair is created. The private key is kept secret, and the public key is shared.
    2. CSR Submission
      A Certificate Signing Request (CSR) is sent to the CA with the public key and identity details.
    3. Verification by CA/RA
      The CA checks the requester’s identity (via DNS, business registration, etc.)
    4. Certificate Issuance
      The CA signs the public key with its private key and issues a certificate.
    5. Certificate Use
      The certificate is installed (e.g. on a web server). Users verify the certificate using the CA’s trusted root.
    6. Revocation (if needed)
      The cert can be revoked by the CA and listed in a CRL or through OCSP.

    🧠 What Is It Used For?

    Use CaseExample
    Web Security (HTTPS)SSL/TLS certificates for sites like https://yourdomain.com
    Email Encryption/SigningS/MIME for Outlook or Thunderbird
    Code SigningCerts to sign software or drivers
    VPN Access & AuthenticationClient certificates for mutual TLS
    Secure MessagingApps like Signal use PKI in background
    Document SigningDigital signatures in PDFs and contracts

    🧭 PKI vs SSL vs TLS

    • PKI is the infrastructure that manages keys and certs
    • SSL/TLS is the protocol used to secure communications
    • SSL is deprecated; TLS 1.2+ is now standard

    🧪 Real-World Examples

    • 🔒 A browser warning: “Your connection is not private” = expired or invalid certificate
    • 🧾 A digitally signed contract PDF = embedded certificate signature
    • 💻 SSH key-pair logins (not certificates) still use public-key crypto

    ✅ Best Practices

    • 🔄 Rotate certificates before expiry
    • 🧪 Validate chain of trust using OpenSSL or certutil
    • 🔐 Store private keys securely (e.g. HSM or encrypted vault)
    • 🚫 Revoke compromised certs immediately
    • 🔍 Monitor for rogue cert issuance (e.g. via CAA or CT logs)

    🧠 Digital certificates are the glue of trust in the digital world — from websites to software, they help verify identity and secure data integrity.

    🔐 Hashing Algorithms and Salt Usage

    🔄 What Is Hashing?

    Hashing is a one-way cryptographic function that converts data (like a password or file) into a fixed-length string (the hash). It’s designed so that:

    • The same input always produces the same output
    • The output cannot be reversed to recover the original input
    • Any small change in input yields a drastically different hash (avalanche effect)

    📦 Example:

    Input: "password123"  
    SHA-256: ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f

    📚 Common Hashing Algorithms

    AlgorithmOutput SizeStrength / Use Case
    MD5128-bitFast but broken — avoid for security use
    SHA-1160-bitAlso broken — only for legacy support
    SHA-256256-bitStrong and widely used (TLS, Bitcoin)
    SHA-512512-bitHigher bit length = more security
    bcryptVariablePurpose-built for password hashing
    scrypt / Argon2VariableSlow and memory-hard — ideal for modern password storage

    🧂 What Is a Salt?

    A salt is a random value added to the input before hashing. It prevents:

    • Attackers from using precomputed hashes (rainbow tables)
    • Identical passwords from producing identical hashes

    📌 Why use it?
    To make brute-force and lookup attacks impractical, even if two users choose the same password.

    📦 Example:

    Password:     "password123"  
    Salt: "Z8x@w9!"
    Hashed Output (bcrypt): $2a$12$Z8xw9abcdefgh...

    💥 Without Salt — What’s the Risk?

    • Two users with the same password will have identical hashes
    • Makes systems vulnerable to rainbow table attacks
    • Easier for attackers to detect reused or weak passwords

    ✅ Best Practices

    • Always use a unique salt per user when storing passwords
    • Use bcrypt, scrypt, or Argon2 for password hashing (they handle salting internally)
    • Never use MD5 or SHA-1 for password storage
    • Do not encrypt passwords—use hash + salt

    🧠 Summary

    FeatureHashingSalting
    One-way Function❌ (not standalone)
    Prevents Reversal
    Stops Lookup Attacks❌ (on its own)
    Password Storage Use✅ (combined)

    🔐 Hashing ensures integrity. Salting ensures uniqueness.
    Together, they keep your users’ secrets safe.

    🔐 SSL/TLS Implementation Guide

    SSL/TLS (Secure Sockets Layer / Transport Layer Security) encrypts data in transit, ensuring that information exchanged between systems (like a user and a website) cannot be intercepted or modified.

    🌐 “If you’re transmitting sensitive data online—encrypt it or risk exposure.”


    📘 What Is SSL/TLS?

    • SSL is the original encryption protocol (now deprecated)
    • TLS is its modern, secure replacement (current version: TLS 1.3)
    • Ensures:
      • 🔒 Confidentiality (via encryption)
      • ✅ Integrity (via message authentication)
      • 🧾 Authenticity (via certificates)

    🔑 Key Components of SSL/TLS

    ComponentPurpose
    CertificateProves server identity (issued by CA)
    Private KeyDecrypts traffic / signs content
    Public KeyDistributed via cert for clients to use
    HandshakeNegotiates secure parameters
    Session KeySymmetric key used for bulk data encryption

    🚀 How to Implement SSL/TLS

    🧰 1. Get a Certificate

    • Use a Certificate Authority (CA) like:
    • Or generate self-signed (for internal use/testing)
    # Generate private key + CSR (Certificate Signing Request)
    openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr

    ⚙️ 2. Configure Your Web Server

    Nginx Example:
    server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/ssl/certs/example.crt;
    ssl_certificate_key /etc/ssl/private/example.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
    try_files $uri $uri/ =404;
    }
    }
    Apache Example:
    <VirtualHost *:443>
    ServerName example.com

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/example.crt
    SSLCertificateKeyFile /etc/ssl/private/example.key
    SSLProtocol all -SSLv2 -SSLv3

    DocumentRoot /var/www/html
    </VirtualHost>

    🔁 3. Redirect HTTP to HTTPS

    Force encryption with a redirect or HSTS header:

    return 301 https://$host$request_uri;

    🧪 4. Test Your TLS Configuration

    testssl.sh https://example.com

    💡 Security Best Practices

    SettingRecommendation
    Minimum TLSEnforce TLS 1.2 or higher
    Disable SSLv2/3Obsolete and insecure
    Use HSTSEnforce HTTPS permanently
    ECDHE Key ExchangeEnables forward secrecy
    Renew CertsAutomatically with Certbot/cron
    Monitor ExpiryAlerts before cert expiration

    ⚠️ Common SSL/TLS Mistakes

    • ❌ Expired or self-signed certificates on public sites
    • ❌ Using outdated protocols like TLS 1.0/1.1
    • ❌ Missing intermediate certificates (chain incomplete)
    • ❌ Not redirecting from HTTP → HTTPS
    • ❌ Reusing private keys across services

    🔒 Summary

    SSL/TLS is your frontline defence for secure communication online. It’s mandatory for any site handling sensitive data, including logins, APIs, and admin panels.

    Encrypt everything, verify authenticity, stay compliant.

    🔐 Modern Cryptography Standards – A 2025 Overview

    Cryptography underpins the confidentiality, integrity, and authenticity of digital communication. As threats evolve, so must the standards we use to encrypt and protect our data.

    💡 “Obsolete crypto isn’t weak because it’s old. It’s weak because attackers have gotten smarter.”


    📚 Categories of Cryptographic Standards

    TypePurposeCommon Algorithms
    SymmetricFast, secure encryptionAES, ChaCha20
    AsymmetricKey exchange, digital signaturesRSA, ECC, Ed25519
    Hash FunctionsOne-way data integritySHA-2, SHA-3, BLAKE3
    Key DerivationPassword security, session keysPBKDF2, bcrypt, Argon2
    Post-QuantumResistance to quantum attacksKyber, Dilithium (NIST finalists)

    🔐 Symmetric Encryption

    AES (Advanced Encryption Standard)

    • Key sizes: 128, 192, 256 bits
    • Block cipher, widely adopted (TLS, full-disk encryption, VPNs)
    • Often used in GCM or CBC modes

    🌀 ChaCha20

    • Stream cipher alternative to AES, used in mobile and TLS
    • Resistant to timing attacks and suitable for low-power devices

    🔑 Asymmetric Encryption

    RSA (2048/3072/4096 bits)

    • Widely used in TLS, SSH, digital signatures
    • Slower than symmetric but essential for key exchange

    🧬 Elliptic Curve Cryptography (ECC)

    • More efficient key sizes (e.g., 256-bit ECC = 3072-bit RSA)
    • Popular curves: secp256r1, Curve25519

    Ed25519

    • Optimised for fast, secure digital signatures
    • Increasingly preferred over traditional RSA in SSH, Git, etc.

    📎 Hashing Algorithms

    SHA-2 (SHA-256, SHA-512)

    • Standard for digital signatures, HMACs, and integrity checks

    🔄 SHA-3

    • Newer standard by NIST, Keccak-based
    • Less common but gaining traction

    BLAKE3

    • Fast, secure, and suitable for large-scale integrity checks

    🔐 Key Derivation & Password Hashing

    AlgorithmUse CaseNotes
    bcryptPassword hashingIncludes salt + configurable cost
    Argon2Modern memory-hard hashingWinner of the Password Hashing Competition
    PBKDF2Legacy password hashingStill used in enterprise, e.g. Wi-Fi WPA2

    🛡️ Digital Signatures

    AlgorithmUse Case
    RSACertificates, PGP, code signing
    ECDSATLS, JWTs, blockchain
    EdDSA (Ed25519)Git commits, SSH, passports

    🧠 Post-Quantum Cryptography (PQC)

    Quantum computers threaten traditional encryption. NIST is finalising standards expected to replace or augment RSA/ECC.

    AlgorithmTypeStatus (as of 2025)
    KyberKey EncapsulationNIST finalist for standardisation
    DilithiumDigital SignaturesLightweight, quantum-safe
    FalconDigital SignaturesFor constrained devices

    🚨 TLS 1.3 + PQ hybrid key exchange is now appearing in forward-looking systems.


    🔒 Modern TLS Standards (2025)

    FeatureRecommendation
    ProtocolTLS 1.2 (minimum) / TLS 1.3
    CiphersuitesAES-GCM, ChaCha20-Poly1305
    Key ExchangeECDHE, X25519, Kyber hybrid
    AuthECDSA, RSA, Ed25519

    Use tools like SSL Labs to validate secure configurations.


    ⚠️ Algorithms to Avoid

    AlgorithmReason
    MD5Broken, collision-prone
    SHA-1Deprecated, insecure
    RC4Weak stream cipher
    DES/3DESObsolete key length
    RSA < 2048Too short to be secure

    ✅ Summary Cheat Sheet

    TaskRecommended Standard
    Data EncryptionAES-256 / ChaCha20
    Key ExchangeECDHE / Kyber hybrid
    Password HashingArgon2 / bcrypt
    Digital SignaturesEd25519 / ECDSA
    TLSTLS 1.3
    File IntegritySHA-256 / BLAKE3

    🔐 Modern crypto is about using the right tool for the right task—securely, efficiently, and with future threats in mind.