Delphi : เข้ารหัส รหัสผ่านด้วย Sha256 ง่ายด้วย System.Hash

ปัจจุบัน ระบบที่เราใช้ไม่ได้มีแค่ Window Application อย่างเดียวเหมือนเมื่อก่อนแล้ว เราอาจมี webapp mobile app ใช้ร่วมกันส่วนที่เป็นปัญหาระหว่างกันคือ

“รหัสผ่าน”

ด้วยว่าเราต้องทำการเข้ารหัส รหัสผ่านของ Usre แต่ละคนซึ่งขึ้นอยู่กับ อัลกอริทึม (Algorithm) ของแต่ละคน แต่เราสามารถใช้ การเข้ารหัสด้วย Function Hash เพื่อ เข้ารหัสด้วย อัลกอริทึม SHA256

Uses

System.Hash

กรณีนี้เราใช้ SHA2

https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.Hash.THashSHA2

Edit2.Text := THashSHA2.GetHashString(Edit1.Text, SHA256);

ซึ่งก็จะได้

“d82494f05d6917ba02f7aaa29689ccb444bb73f20380876cb05d1f37537b7892”

หากเราใช้ Web เป็น PHP

เราใช้ Function Hash ใน PHP

<?php

echo hash(‘sha256’, ‘adminadmin’);

?>

ผลลัพธ์ที่ได้

“d82494f05d6917ba02f7aaa29689ccb444bb73f20380876cb05d1f37537b7892”

เมื่อนำมาเปรียบเทียบกันกับที่ได้จาก Delphi

“d82494f05d6917ba02f7aaa29689ccb444bb73f20380876cb05d1f37537b7892”

ก็จะได้ผลลัพธ์เหมือนกัน ทีนี้เราก็ใช้ User และ รหัสผ่าน เดียวกับ Platform อื่นได้แล้วครับ

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response

More from Piyanat Nimkhuntod