> For the complete documentation index, see [llms.txt](https://rs0-5.gitbook.io/righttech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rs0-5.gitbook.io/righttech/common/hash.md).

# Hash Function และ SHA-256

#### ❖ Hash คืออะไร?

Hash Function (ฟังก์ชันแฮช) คือกระบวนการคำนวณทางคณิตศาสตร์ที่แปลงข้อมูลใด ๆ ให้เป็นชุดของอักขระที่มีความยาวคงที่ เช่น ตัวเลขและตัวอักษร ซึ่งเรียกว่า “hash value” หรือ “digest”

ลักษณะสำคัญของ Hash:

* 📌 **Deterministic**: ข้อมูลเดียวกันจะได้ค่าแฮชเดียวกันเสมอ
* 🔐 **One-way**: ไม่สามารถย้อนกลับจากค่าแฮชไปเป็นข้อมูลเดิมได้
* 💥 **Collision-resistant**: หลีกเลี่ยงการมีข้อมูลต่างกันแต่ให้ค่าแฮชเหมือนกัน
* ⚡ **Fast computation**: คำนวณได้รวดเร็วแม้ข้อมูลขนาดใหญ่

#### ❖ SHA-256 คืออะไร?

**SHA-256 (Secure Hash Algorithm 256-bit)** คือหนึ่งในกลุ่มของ SHA-2 algorithm ที่พัฒนาโดย National Security Agency (NSA) และรับรองโดย NIST

**จุดเด่นของ SHA-256:**

* แฮชขนาด 256 บิต (64 ตัวอักษร hex)
* เป็นหนึ่งในอัลกอริทึมที่มั่นคงปลอดภัยที่สุดในปัจจุบัน
* ใช้ในระบบต่าง ๆ เช่น:
  * ✅ **Bitcoin**: การทำงานของบล็อกเชนและการขุดเหรียญ
  * 🔐 **Digital Signature**
  * 📁 **File Integrity Verification**

```
ข้อมูล: hello
SHA-256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
```

#### ❖ SHA-256 ในระบบ Bitcoin

ในระบบของ Bitcoin:

* เมื่อมีการทำธุรกรรมใหม่ → ข้อมูลจะถูกนำมาสร้าง block
* ทุก block จะมี **Hash ของ block ก่อนหน้า** เป็นส่วนประกอบ → เกิดความเชื่อมโยง (chain)
* ผู้ขุด (Miner) ต้องหาค่า nonce ที่เมื่อนำมารวมกับข้อมูลแล้วให้ hash เริ่มต้นด้วยศูนย์หลายตัว → เป็นกระบวนการ **Proof-of-Work**

ผลลัพธ์:\
✔ ระบบปลอดการปลอมแปลง\
✔ ใคร ๆ ก็ตรวจสอบย้อนหลังได้\
✔ ไม่ต้องใช้ตัวกลาง (Decentralized)

***

#### ❖ สรุป

SHA-256 คือหัวใจของความปลอดภัยในหลายระบบ โดยเฉพาะ **Bitcoin** ที่พึ่งพา Hash อย่างสมบูรณ์ในการรักษาความถูกต้องของข้อมูลและความโปร่งใสของธุรกรรม ด้วยความแข็งแกร่งและความเร็วในการคำนวณ ทำให้ SHA-256 ยังคงเป็นมาตรฐานความปลอดภัยในยุคดิจิทัล

<figure><img src="/files/a8JKchXrV2beJu9pabpc" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://rs0-5.gitbook.io/righttech/common/hash.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
