0Pricing
Web3 & DApp Development Fundamentals · บทเรียน

วิทยาการเข้ารหัสสำหรับบล็อกเชน

ทำความเข้าใจฟังก์ชันแฮช การเข้ารหัสด้วยกุญแจสาธารณะ และลายเซ็นดิจิทัลที่ใช้ในเทคโนโลยีบล็อกเชน

วิทยาการเข้ารหัสสำหรับบล็อกเชน เป็นบทเรียน Web3 & DApp Development Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 3 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web3 & DApp Development Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 3 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Crypto: The Blockchain's Secret Sauce

Welcome to Cryptography for Blockchains! Cryptography is the backbone of blockchain technology, ensuring security, integrity, and trust.

In this lesson, we'll unlock the secrets of hash functions, public-key cryptography, and digital signatures – key concepts that make decentralized systems possible.

Hashing: A Digital Fingerprint

Imagine taking any amount of data – a text, an image, a whole book – and turning it into a unique, fixed-size string of characters. That's what a hash function does!

It's like a digital fingerprint for your data. Even a tiny change in the original data will produce a completely different fingerprint.

Superpowers of Crypto Hashes

Cryptographic hash functions have special properties that make them perfect for blockchains:

  • One-way: Easy to compute the hash, but nearly impossible to reverse-engineer the original data from the hash.
  • Deterministic: The same input will always produce the exact same output hash.
  • Collision-resistant: It's extremely hard to find two different inputs that produce the same hash output.
  • Avalanche Effect: A tiny change in input results in a drastically different hash output.

Hashing Demo: See it in Action!

Let's see the avalanche effect with a common hashing algorithm, SHA-256 (Secure Hash Algorithm 256-bit). Notice how a small change alters the hash completely.

import java.security.MessageDigest;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Main {
  public static String applySha256(String input) {
    try {
      MessageDigest digest = MessageDigest.getInstance("SHA-256");
      byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
      StringBuilder hexString = new StringBuilder();
      for (byte b : hash) {
        String hex = Integer.toHexString(0xff & b);
        if (hex.length() == 1) hexString.append('0');
        hexString.append(hex);
      }
      return hexString.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public static void main(String[] args) {
    String data1 = "Hello CoddyKit!";
    String data2 = "hello CoddyKit!"; // Note: 'h' vs 'H'

    System.out.println("Data 1 Hash: " + applySha256(data1));
    System.out.println("Data 2 Hash: " + applySha256(data2));
  }
}

Hashes: Linking Blocks & Data

In blockchains, hashes are fundamental:

  • Block Linking: Each block contains the hash of the previous block. This creates an unbreakable chain, making it nearly impossible to alter past transactions without invalidating subsequent blocks.
  • Data Integrity: A block's hash is calculated from all its data (transactions, timestamp, etc.). If even one piece of data is tampered with, the block's hash changes, immediately revealing the alteration.

Public-Key Crypto: Two Keys, One Lock

Public-key cryptography (also called asymmetric cryptography) uses a pair of mathematically linked keys: a public key and a private key.

Think of it like a special mailbox: anyone can put a letter in (encrypt with public key), but only the person with the unique key can open it (decrypt with private key).

Your Digital Identity: Keys

This key pair is crucial:

  • Private Key: This is your secret. It's like your password and signature rolled into one. You must never share it! It's used to decrypt messages or create digital signatures.
  • Public Key: This is derived from your private key and can be shared openly. It's used by others to encrypt messages for you or to verify your digital signatures.

These keys allow secure communication without ever sharing a secret directly.

Digital Signatures: Proving Authenticity

A digital signature is a cryptographic technique used to verify the authenticity and integrity of a digital message or document.

It's like a handwritten signature, but far more secure! It confirms that the message truly came from the signer and hasn't been altered since it was signed.

Signing & Verifying Digitally

Here's how it generally works:

  1. The sender hashes the message.
  2. They encrypt this hash with their private key to create the digital signature.
  3. The receiver gets the message and the signature.
  4. They hash the received message themselves.
  5. They decrypt the sender's signature using the sender's public key to get the original hash.
  6. If the two hashes match, the signature is valid, and the message is authentic and untampered!

Quick Check: Cryptography

Which of the following is NOT a core property of a cryptographic hash function?

Recap: Crypto's Role in Web3

Great job! You've learned the cryptographic fundamentals that power Web3:

  • Hash Functions: Create unique, fixed-size 'fingerprints' for data, ensuring integrity and linking blocks.
  • Public-Key Cryptography: Uses key pairs (public/private) for secure communication and identity.
  • Digital Signatures: Provide authenticity and non-repudiation for transactions, vital for blockchain security.

These concepts are crucial for understanding how cryptocurrencies and decentralized applications remain secure and trustworthy. Next, we'll dive deeper into how these keys are managed in wallets!

คำถามที่พบบ่อย

บทเรียน “วิทยาการเข้ารหัสสำหรับบล็อกเชน” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “วิทยาการเข้ารหัสสำหรับบล็อกเชน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web3 & DApp Development Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 3 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “วิทยาการเข้ารหัสสำหรับบล็อกเชน”

ทำความเข้าใจฟังก์ชันแฮช การเข้ารหัสด้วยกุญแจสาธารณะ และลายเซ็นดิจิทัลที่ใช้ในเทคโนโลยีบล็อกเชน คุณปฏิบัติ Web3 & DApp Development Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web3 & DApp Development Fundamentals หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web3 & DApp Development Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 3 บทเรียน

บทเรียน “วิทยาการเข้ารหัสสำหรับบล็อกเชน” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Web3 & DApp Development Fundamentals นี้ได้ไหม

ได้ บทเรียน Web3 & DApp Development Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. วิทยาการเข้ารหัสสำหรับบล็อกเชน
  2. กุญแจสาธารณะ/ส่วนตัวและกระเป๋าเงิน
  3. บทนำสู่ MetaMask
← กลับไปที่ Web3 & DApp Development Fundamentals