> For the complete documentation index, see [llms.txt](https://manual.seara.biz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.seara.biz/appendix/check-file-hash-with-sha256.md).

# check file HASH with SHA256

แสดงตัวอย่างวิธีการทดสอบ Logfile ด้วย Hash Function แบบ SHA256 เพื่อตรวจสอบว่าไฟล์ดังกล่าวถูกต้องและไม่มีการแก้ไข

การทำ HASH ด้วย วิธีการ [SHA256](https://en.wikipedia.org/wiki/SHA-2) (Secure hash algolithm) เป็นวิธีการเปลี่ยน Input ที่มีขนาดใดๆให้เป็น Output ขนาด 256 Bit ด้วยอัลกอริทึม [SHA256](https://en.wikipedia.org/wiki/SHA-2) ซึ่งไว้ตรวจสอบว่าข้อมูล Input ดังกล่าวไม่มีการถูกแก้ไขเปลี่ยนแปลงใดๆ การทำ HASH ดังกล่าวเพื่อแสดงความคงสถาพของข้อมูลนั้นๆ ซึ่งการแก้ไข Input แค่เพียง 1 ตัวอักษรจะทำให้ค่า HASH ที่ได้รับเปลี่ยนแปลงไปทันทีโดยสิ้นเชิง ผู้ดูแลระบบสามารถตรวจสอบคงสภาพของข้อมูลได้โดยง่าย จากการเรียกใช้ อัลกอริทึม [SHA256 ](https://en.wikipedia.org/wiki/SHA-2)จาก Website ต่างๆหรือ Load โปรแกรมที่ทำหน้าที่ดังกล่าวมาติดตั้งไว้ในเครื่องคอมพิวเตอร์ ในที่นี้จะขอยกตัวอย่าง website ที่ให้บริการทำ HASH ด้วยวิธีการ [SHA256](https://en.wikipedia.org/wiki/SHA-2) เช่น

{% embed url="<https://emn178.github.io/online-tools/sha256.html>" %}
<https://emn178.github.io/online-tools/sha256.html>
{% endembed %}

<figure><img src="https://71561992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M-OjnKhMWq_4gll0i0s%2Fuploads%2F5izEoZcUizlqzRs4PN4J%2Fsha256%20hello%20world.png?alt=media&amp;token=72c98aca-d5bd-4c74-8f2e-f0d254d0a724" alt=""><figcaption><p>ตัวอย่างการสร้าง SHA256</p></figcaption></figure>

ยกตัวอย่างเช่น เมื่อใช้ค่า Input เป็น Hello World จะได้ค่า output ที่ผ่านการทำ SHA256 เป็น 64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c

<figure><img src="https://71561992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M-OjnKhMWq_4gll0i0s%2Fuploads%2FL9vFZqpQshPsX8dwuEFE%2Fsha256%20hello%20warld.png?alt=media&amp;token=a32334d5-7fce-45df-ad49-85af6d5b1918" alt=""><figcaption></figcaption></figure>

เมื่อทดสอบเปลี่ยนค่า Input เป็น Hello Warld  (เปลี่ยนจาก World เป็น Warld) จะได้ค่า output เป็น afab019330eb8ab403ba8400e52eb9008fdf7652ce9397ddc4839b4d5be4c1ac ซึ่งจะต่างกันโดยสิ้นเชิงทั้งๆที่ข้อความ Input เปลี่ยนแปลงเพียงตัวอักษรเดียวเท่านั้น&#x20;

ในการตรวจสอบความคงสภาพของข้อมูลใน Seara สามารถทดสอบได้ด้วยวิธีการเดียวกันโดยใช้ Input เป็น Logfile ที่ตอบการทดสอบ <mark style="color:red;">(ใช้นามสกุล.gz ได้เลยโดยไม่ต้องแตก File)</mark> โดย Upload เข้าไปยัง Website ระบบจะดำเนินการคำนวณค่า HASH ด้วยวิธีการ SHA256 ของ file ดังกล่าว และเราสามารถนำ output ที่ได้มาเทียบกับค่าที่ถูกเก็บไว้ในฐานข้อมูลของระบบเพื่อตรวจสอบว่าตรงกันหรือไม่ ยกตัวอย่างเช่น&#x20;

<figure><img src="https://71561992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M-OjnKhMWq_4gll0i0s%2Fuploads%2FNiiq5JjLmPayi5fXvxpu%2FScreenshot%202023-03-01%20at%2009.17.55.png?alt=media&amp;token=ee282f65-b924-40b8-ac75-4329d8717166" alt=""><figcaption><p>ตัวอย่างการ ตรวจสอบ Logfile</p></figcaption></figure>

firewall.log-2023-02-26H23.gz เป็นไฟล์ Internet Traffic Log เมื่อวันที่ 26 เดือนกุมภาพันธ์ 2023 เวลา 22.00-23:00 เมื่อตรวจสอบ ![](https://71561992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M-OjnKhMWq_4gll0i0s%2Fuploads%2Fq6eF1a31rZJNrB1LhBCa%2FScreenshot%202023-03-01%20at%2009.21.28.png?alt=media\&token=6cc26f95-6762-4cb7-8aad-fead01ac2c2a) ในระบบจะได้ค่าดังนี้ 4d042baa1ad70c656546ef25ccd9827721cbfdbfa0e221e3e583af621219fea1

ตรวจสอบค่าโดย Download file ดังกล่าวไปตรวจสอบที่ Website

{% embed url="<https://www.strerr.com/en/sha256_file.html>" %}

จะได้ค่า 4d042baa1ad70c656546ef25ccd9827721cbfdbfa0e221e3e583af621219fea1 ตามรูป

<figure><img src="https://71561992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M-OjnKhMWq_4gll0i0s%2Fuploads%2Fq87hY5eXsB2p1595Knv1%2FScreenshot%202023-03-01%20at%2009.25.44.png?alt=media&amp;token=fdf6e513-5249-447b-9b45-f56e9c279b7b" alt=""><figcaption></figcaption></figure>

ซึ่งจะพบว่าตรงกันกับค่า ![](https://71561992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M-OjnKhMWq_4gll0i0s%2Fuploads%2Fq6eF1a31rZJNrB1LhBCa%2FScreenshot%202023-03-01%20at%2009.21.28.png?alt=media\&token=6cc26f95-6762-4cb7-8aad-fead01ac2c2a) ที่ถูกเก็บไว้ในฐานข้อมูลดังนั้นจึงสามารถพิสูจน์ได้ว่า file ดังกล่าวมีข้อมูลที่ถูกต้องและไม่มีการแก้ไขเปลี่ยนแปลงข้อมูลใดๆ
