SlideShare a Scribd company logo
1 of 27
Download to read offline
IT346 Information System Security
Week 4-2: Hash Function
& Digital Signature
ผศ.ดร.มัชฌิกา อ่องแตง

Faculty of Information Technology

Page

1
Cryptography
Cryptography หมายถึงวิทยาการรหัสลับ มาจากคําว่า crypto ที่แปลว่า
ซ่อน และคําว่า graph ที่แปลว่าการเขียนCryptography จึงมีความหมาย
ว่า “การเขียนเพื่อซ่อนข้อมูล”
Cryptography ใช้ในการป้องกันข้อมูลและสารสนเทศ โดยประกอบด้วย 3
เทคโนโลยีหลัก
‣ Symmetric Key Cryptography หรือ Secret Key Cryptographyคือการ

เข้ารหัสข้อมูลแบบ “สมมาตร”
‣ Asymmetric Key Cryptography หรือ Public Key Cryptographyคือการ
เข้ารหัสข้อมูลแบบ “อสมมาตร”
‣ Hash Function คือการสร้างตัวแทนข้อมูล

Faculty of Information Technology

Page

2
Hash / Message Digest
เมื่อต้องการรักษา Integrity (ความถูกต้องสมบูรณ์) ของข้อมูล เราใช้
เทคนิคการแปลงรูปแบบของข้อมูลที่รับเข้ามาให้เป็นข้อมูลที่ถูกย่อย
(Message Digest) Message Digest ที่เรียกว่าเทคนิคการ Hash
นําข้อมูลไปดําเนินการผ่าน One-Way Hash Function ซึ่งจะเปลี่ยน
message ขนาดใหญ่ให้มีขนาดเล็ก และมีขนาดคงที่ไม่ว่า message ดั้งเดิม
จะมีขนาดเท่าไรก็ตาม
hm = h(m)

เราไม่สามารถทํากระบวนการย้อนกลับเพื่อให้กลายเป็นข้อมูลต้นฉบับได้ แต่
เราสามารถใช้ Hash ในการตรวจสอบว่าข้อมูลที่ให้มาแต่ละครั้งตรงกับที่เรา
ต้องการหรือไม่ หรือไฟล์นั้นมีการเปลี่ยนแปลงโดยคนอื่นหรือไวรัสหรือไม่
Faculty of Information Technology

Page

3
Hash / Message Digest
คุณสมบัติของ One-Way Hash Function คือ
‣ เราไม่สามารถ (ในทางปฏิบัติ) คํานวณ message จาก hash ของมันได้ (One-

Way) นั่นคือ หากมี h(m) เราไม่สามารถคํานวณหา m ได้
‣ เราไม่สามารถ (ในทางปฏิบัติ) คํานวณหา message 2 อันที่มี hash ตรงกันได้
‣ เราไม่สามารถ (ในทางปฏิบัติ) แก้ไข message โดยรักษาค่า hash ให้คงเดิมได้
‣ สามารถคํานวณได้อย่างรวดเร็วและไม่ต้องใช้ทรัพยากรมาก

ตัวอย่าง Hash Function ได้แก่
‣ Message Digest (MD) เช่น MD-4, MD-5
‣ Secure Hash Algorithm เช่น SHA-1, SHA-2

Faculty of Information Technology

Page

4
Hash Function ที่นิยม
MD5 คิดค้นโดย Ron Rivest ซึ่งเป็น 1 ใน 3 คนที่คิดค้น RSA
‣ แม้ MD5 จะได้รับความนิยมอย่างมาก และได้มีการนํามาใช้แพร่หลายเช่น

นํามาใช้สร้าง Digital Signature ในระบบ e-commerce อย่างไรก็ตาม MD5
ก็ถูก break ได้โดย Professor Dr. Xiaoyun Wang ในปี 2004 โดยใช้เครื่อง
ซูเปอร์คอมพิวเตอร์ IBM P690 และใช้เวลา Crack 1 ชั่วโมงก็สามารถ break
ได้ หลังจากนั้นก็มีคนอ้างว่าสามารถใช้เครือง Notebook ความเร็ว 1.6 GHz
่
เบรค MD5 ได้ภายในเวลา 8 ชั่วโมง

SHA-0 และ SHA-1 ได้ถูกพัฒนาให้มีความแข็งแรงกว่า MD5
‣ พัฒนาจาก MD5 เดิมให้ Output มีความเป็น Random สูงกว่า และมี

Collision น้อยกว่าเพื่อลดโอกาสในการถูก Crack ได้
‣ SHA0 และ SHA1 ก็ถูกเบรคได้โดย Professor Dr. Xiaoyun Wang เช่นกัน
‣ SHA2 ซึ่งยังไม่มีใคร break ได้
Faculty of Information Technology

Page

5
ตัวอย่าง 1: การใช้งาน Hash
โดยปกติ เราใช้งาน Hash เพื่อตรวจสอบ Integrity ของข้อมูล
‣ Alice กับ Bob แชร์ Secret Key K ด้วยกัน ใช้ในการ Encrypt ข้อมูล
‣ Alice ส่งข้อมูล M ให้ Bob ดังนี้
• Encrypt ข้อมูล M ด้วย key K ได้เป็น EK(M)
ทําเพื่อรักษา Security Goal ใด?
• คํานวณ h(M) แล้วนําผลลัพธ์ที่ได้แนบไปกับ EK(M)
ทําเพื่อรักษา Security Goal ใด?
h(M) | EK(M)

Bob

Alice

Note:
Faculty of Information Technology

F

ˈ

F

Encrypt h(M)?
Page

6
ตัวอย่าง 1: การใช้งาน Hash
‣ Bob สามารถตรวจสอบ Integrity ของข้อมูลที่รับมาได้ ดังนี้
• Decrypt EK(M) ด้วย Key K เพื่อให้ได้ M
• คํานวณ h(M)
• เปรียบเทียบ h(M) ที่ตนคํานวณได้ กับ h(M) ที่ Alice แนบมา หากเท่ากัน แปลว่า
ไม่ได้มีใครเปลี่ยนแปลง M
h(M) | EK(M)

Bob

Alice

h(M) | EK(M)
Decrypt

=?

M
hash

h(M)
Faculty of Information Technology

Page

7
ตัวอย่าง 2: การใช้งาน Hash
ผู้ใช้ machigar ตั้ง password เป็นคําว่า abc123
‣ หากเก็บรหัสผ่านลงบน Database โดยตรงจะทําให้ผู้ใดก็ตามที่เข้าถึงฐานข้อมูล

ได้ ทราบรหัสผ่านที่เก็บไว้ (ผู้ที่เข้าถึงฐานข้อมูลได้เช่นผู้ดูแลระบบ ผู้ดูแล
ฐานข้อมูล และแฮกเกอร์ที่อาจเจาะเข้ามาในระบบ

เพื่อให้เก็บ password ได้อย่างปลอดภัย ระบบทําการสร้างตัวแทนรหัสผ่าน
ด้วยฟังก์ชั่น Hash (สร้าง h(password))
‣ ตัวอย่าง ใช้อลกอริธึม MD5 ย่อยรหัสผ่าน abc123 ได้เป็น
ั

h(abc123) = e99a18c428cb38d5f260853678922e03

ระบบเก็บ h(password) ลงใน Database แทนที่จะเก็บ password
โดยตรง ทําให้การเปิดดูรหัสผ่านใน Database ไม่พบ password แต่จะพบ
เพียงค่า h(password) ที่เก็บไว้แทน
Faculty of Information Technology

Page

8
ตัวอย่าง 2: การใช้งาน Hash
การเก็บ h(password) แทนค่า password เป็นการป้องกันการเปิดเผย
password
‣ เราไม่สามารถใช้ค่า h(password) ในการคํานวณย้อนกลับไปเป็น password

ได้

ในการตรวจสอบสิทธิ์ผู้ใช้แต่ละครั้งสําหรับการล็อกอินทําได้โดย
‣ นํา password ที่ผู้ใช้ป้อนเข้ามาไปผ่านฟังก์ชั่น Hash เพื่อคํานวณหา

h(password)
‣ นําค่า h(password) ทื่ได้มาเทียบกับค่า h(password) ที่เก็บไว้ใน Database
หากมีค่าตรงกันก็แสดงว่ารหัสผ่านถูกต้อง

Faculty of Information Technology

Page

9
ตัวอย่างการใช้งาน Hash
password
password

h(password)

Password
Database

hash

=?
h(password)

ˆ
ก ก
F
Faculty of Information Technology

F
ก
F Moodle

F

Linux
ก F Fก

ก

F
F

F

ก
MD5
Web Application

Mambo
Page

10
กิจกรรมที่ 1
จับคู่เพื่ออภิปรายกรณีการใช้เทคโนโลยี Cryptography เพื่อปกป้องการ
สื่อสารต่อไปนี้
การสื่อสารนี้รักษา Confidentiality, Integrity หรือไม่ อย่างไร
EK(M)

Bob

Alice

การสื่อสารนี้รักษา Confidentiality, Integrity หรือไม่ อย่างไร
M | h(M)

Alice
Faculty of Information Technology

Bob
Page

11
กิจกรรมที่ 1
การสื่อสารรักษา Confidentiality, Integrity หรือไม่ อย่างไร
h(M) | EK(M)

Bob

Alice

การสื่อสารนี้รักษา Confidentiality, Integrity หรือไม่ อย่างไร
EK(M | h(M))

Alice

Faculty of Information Technology

Bob

Page

12
Message Authentication Code (MAC)
MAC คือการเข้ารหัสข้อมูลเพื่อใช้ในการพิสูจน์ความคงสภาพของข้อมูล
โดยจะใช้ Secret Key และข้อความที่มีความยาวเท่าใดก็ได้ และคํานวณ
ออกมาเป็น MAC
‣ การพิสูจน์ทราบข้อมูลนั้นผู้ตรวจสอบจะต้องมี Secret Key เดียวกัน

เรา encrypt ค่า hash ของ message เพื่อสร้างเป็น message
authentication code (MAC) ของ message จากนั้นจึงต่อส่วน MAC
เข้าไปกับ message

Faculty of Information Technology

Page

13
Message Authentication Code (MAC)
กระบวนการสร้าง MAC
Message M
Hash Algorithm
MAC

Message M

hash(M)
Secret
Key

encryption
MAC

EK(h(M)) | M

การใช้งาน MAC ในลักษณะนี้ รักษา Confidentiality หรือไม่?
Faculty of Information Technology

Page

14
Message Authentication Code (MAC)
กระบวนการตรวจสอบ MAC
Message M

MAC
Secret
Key

decryption

Hash Algorithm

h(M)

h(M)
=?

Faculty of Information Technology

Page

15
Asymmetric-Key Cryptography
Asymmetric-key Cryptography เพื่อรักษา confidentiality
‣ Encrypt ข้อมูลที่ต้องการปกปิดด้วย public key ของผู้รบ
ั
Private Key
Public Key
Ciphertext
Plaintext
Plaintext
Decryption
Encryption
E(P, PKreceiver) = C

P = Plaintext
C = Ciphertext
PK = Public Key
SK = Private Key

D(C, SKreceiver) = P

Asymmetric-key Cryptography เพื่อรักษา Non-Repudiation
‣ Encrypt ข้อมูลที่ต้องการยืนยันด้วย private key ของผูสง
้่
Public Key
Private Key
Plaintext

Encryption

E(P, SKsender) = C
Faculty of Information Technology

Ciphertext

Decryption

Plaintext

D(C, PKsender) = P
Page

16
Digital Signatures
การทําธุรกรรมอิเล็คทรอนิกส์จําเป็นที่จะต้องมีการยืนยันเอกสารหรือข้อมูลที่
ส่งว่าถูกส่งมาจากผู้ส่งจริง เพื่อการป้องกันการปฏิเสธการทําธุรกรรม (Nonrepudiation) และเป็นการพิสูจน์ทราบตัวตน (Authentication) ของ
ผู้สร้างเอกสาร
จาก Asymmetric Key Cryptography เราทราบว่าการเข้ารหัสข้อมูล
ด้วย Private Key สามารถยืนยันผู้ส่งได้
‣ เช่นผู้ใช้ A เข้ารหัสข้อมูลด้วย Private Key ของตนเองแล้วส่งข้อมูลไปให้ผู้ใช้ B

และผู้ใช้ C จากนั้นผู้ใช้ B และผู้ใช้ C ก็ถอดรหัสโดยใช้ Public Key ของผู้ใช้ A
ได้ เป็นการยืนยันได้ว่าข้อมูลมาจากผู้ใช้ A จริง เพราะเป็นคนเดียวที่มี Private
Key ของผู้ใช้ A

Faculty of Information Technology

Page
Digital Signature
ลายเซ็นอิเล็กทรอนิกส์ (Digital Signature) อาศัย Asymmetric Key
Cryptography เพื่อเป็นการรับรองว่าผู้ส่งนั้นเห็นด้วยกับข้อความที่ส่งและ
ข้อความส่งถึงผู้รับโดยไม่มีการเปลี่ยนแปลงโดยบุคคลที่สาม เนื้อหาอาจจะ
เปิดเผยได้
เทียบได้กับลายเซ็นกํากับการทําธุรกรรมบนกระดาษ

Faculty of Information Technology

Page

18
Digital Signature
นอกจากเราใช้ public-private key pair ในการรักษา confidentiality
โดยการใช้ public key ในการ encrypt ข้อมูลแล้ว เรายังสามารถใช้
private key ในการ encrypt ข้อมูล เพื่อพิสูจน์ตัวตนของแหล่งที่มาของ
ข้อมูลได้ (message authentication)
‣ เฉพาะผู้ส่งทีแท้จริงเท่านั้นทีสามารถ encrypt ข้อมูลได้ เนื่องจาก private key
่
่

จะรู้เฉพาะผู้ส่งเท่านั้น

เมื่อ encrypt ด้วย private key จะต้อง decrypt ด้วย public key ที่
สัมพันธ์กัน
E(P, SKsender) = C

Faculty of Information Technology

E(C, PKsender) = P

Page

19
แนวคิดการทํา Enveloping
เนื่องจาก symmetric key cryptography ใช้เวลาดําเนินการต่ํา จึงนิยม
มากกว่าในการ encrypt ข้อมูลมากๆ
เราสามารถใช้ public key encryption เป็นกลไกในการส่ง secret
(symmetric) key ได้
Message m
Ks
Random Key

Symmetric Encryption

PKreceiver encryption
E(Ks, PKreceiver)
Faculty of Information Technology

E(m, Ks)
Page

20
Enveloping ใน Digital Signature
ในการส่งข้อมูลที่มีขนาดใหญ่ หากต้องการที่จะยืนยันผู้ส่งด้วยวิธีการข้างต้น
เราจะต้องทําการเข้ารหัสข้อมูลทั้งหมดด้วย Private Key ของผู้ส่ง (เพื่อ
เป็นการยืนยันตัวตนผู้ส่ง)
‣ ข้อเสียคือจะต้องมีการเข้ารหัสข้อมูลขนาดใหญ่ทงหมด และผู้รับจะต้องทําการ
ั้

ถอดรหัสข้อมูลทั้งหมดเช่นกัน ซึ่งทําให้เปลือง CPU และเปลืองเวลาในการ
ประมวลผล

หากข้อมูลที่จะส่งนั้น "ไม่เป็นความลับ“ เราสามารถที่จะประยุกต์ใช้การทํา
Enveloping ให้ใช้ CPU และเปลืองเวลาน้อยลงได้โดยใช้ฟังก์ชั่น Hash
‣ เนื่องจากข้อมูลไม่เป็นความลับ จึงไม่ทํา Secret Key Encryption แต่ทําการ

hash แทน เพื่อให้ข้อมูลขนาดเล็กลง

Faculty of Information Technology

Page
Enveloping ใน Digital Signature
เนื่องจากการดําเนินการ public key cryptosystem มักใช้เวลาใน
ดําเนินการสูง เราจึงนิยมทํา message authentication โดยการ encrypt
ส่วน Message Authentication Code (MAC) ซึ่งมีขนาดเล็กว่า และ
encrypt ได้รวดเร็วกว่าแทน เรียกว่า Digital Signature (DS)
Message m
Hash Algorithm
DS

Message m

h(m)
SKsender encryption
DS
Faculty of Information Technology

SK = Private Key
Page

22
Digital Signature
ขั้นตอนในการทํา Digital Signature
‣ ข้อมูลที่ต้องการจะส่งจะถูกคํานวณให้ได้ข้อความทีสั้นลงโดยใช้ Hash Function
่

ผลทีได้จะเป็นข้อมูลสั้นๆ และความยาวคงที่ ซึ่งเรียกว่า Message Digest
่
‣ ผู้ส่งจะเซ็นชื่อในข้อความโดยการ Encrypt ตัว Message Digest h(m) โดยใช้
Private Key ของตัวเอง เรียกผลลัพธ์ดังกล่าวว่า Digital Signature
‣ ข้อความเดิมจะถูกส่งไปพร้อมกับ Digital Signature นี้ไปให้ผู้รับ
‣ ผู้รับทําการตรวจสอบข้อมูลทีได้รับ
่

DS = E(h(m), SKsender)

Faculty of Information Technology

Page

23
Digital Signature
ขั้นตอนในการตรวจสอบ Digital Signature
DS

Message m
Hash Algorithm

PKsender decryption

h(m)

h(m)
=?

Faculty of Information Technology

Page

24
Faculty of Information Technology

Page

25
ประโยชน์ของการใช้ลายเซ็นดิจิทัล
พิสูจน์ได้ว่าข้อมูลที่รับมานั้นมาจากผู้ส่งตัวจริง และไม่ได้ถูกปลอมแปลง
(Authentication)
พิสูจน์ได้ว่าข้อมูลได้ถูกเปลี่ยนแปลงหรือไม่ (Data Integrity)

Faculty of Information Technology

Page

26
กิจกรรมที่ 2
จับกลุ่ม กลุ่มละ 3 คน เพื่ออภิปรายความแตกต่างระหว่าง Message
Integrity Code (MAC) และ Digital Signature
‣ การทํางานและโครงสร้างของ MAC และ Digital Signature ต่างกันอย่างไร
‣ ความแตกต่างดังกล่าวทําให้ MAC และ Digital Signature ให้คุณสมบัติด้าน

การรักษาความมั่นคงปลอดภัยต่างกันอย่างไร

Faculty of Information Technology

Page

27

More Related Content

What's hot

Transposition cipher
Transposition cipherTransposition cipher
Transposition cipherAntony Alex
 
Ethical hacking - Skills.pptx
Ethical hacking - Skills.pptxEthical hacking - Skills.pptx
Ethical hacking - Skills.pptxNargis Parveen
 
Password Attack
Password Attack Password Attack
Password Attack Sina Manavi
 
Privacy and Data Security
Privacy and Data SecurityPrivacy and Data Security
Privacy and Data SecurityWilmerHale
 
Encryption technology
Encryption technologyEncryption technology
Encryption technologyNeha Bhambu
 
Cyber Crime Investigation
Cyber Crime InvestigationCyber Crime Investigation
Cyber Crime InvestigationHarshita Ved
 
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - ErykData Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - ErykEryk Budi Pratama
 
History and future cybercrime
History and future cybercrimeHistory and future cybercrime
History and future cybercrimeOnline
 
Security Policies and Standards
Security Policies and StandardsSecurity Policies and Standards
Security Policies and Standardsprimeteacher32
 
Cybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber SecurityCybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber SecurityEryk Budi Pratama
 
Mobile Forensics and Cybersecurity
Mobile Forensics and CybersecurityMobile Forensics and Cybersecurity
Mobile Forensics and CybersecurityEric Vanderburg
 
Information security in todays world
Information security in todays worldInformation security in todays world
Information security in todays worldSibghatullah Khattak
 

What's hot (20)

Transposition cipher
Transposition cipherTransposition cipher
Transposition cipher
 
Ethical hacking - Skills.pptx
Ethical hacking - Skills.pptxEthical hacking - Skills.pptx
Ethical hacking - Skills.pptx
 
Password Attack
Password Attack Password Attack
Password Attack
 
Privacy and Data Security
Privacy and Data SecurityPrivacy and Data Security
Privacy and Data Security
 
Encryption technology
Encryption technologyEncryption technology
Encryption technology
 
Cyber Crime Investigation
Cyber Crime InvestigationCyber Crime Investigation
Cyber Crime Investigation
 
Monitoring, Detecting And Preventing Insider Fraud And Abuse V2
Monitoring, Detecting And Preventing Insider Fraud And Abuse V2Monitoring, Detecting And Preventing Insider Fraud And Abuse V2
Monitoring, Detecting And Preventing Insider Fraud And Abuse V2
 
Ch02 classic nemo
Ch02 classic nemoCh02 classic nemo
Ch02 classic nemo
 
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - ErykData Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
 
Cryptography
CryptographyCryptography
Cryptography
 
Cyber security
Cyber securityCyber security
Cyber security
 
History and future cybercrime
History and future cybercrimeHistory and future cybercrime
History and future cybercrime
 
CNS - Unit - 4 - Public Key Cryptosystem
CNS - Unit - 4 - Public Key Cryptosystem CNS - Unit - 4 - Public Key Cryptosystem
CNS - Unit - 4 - Public Key Cryptosystem
 
Security Policies and Standards
Security Policies and StandardsSecurity Policies and Standards
Security Policies and Standards
 
Data Security Explained
Data Security ExplainedData Security Explained
Data Security Explained
 
Information security
Information securityInformation security
Information security
 
Fundamentals of cryptography
Fundamentals of cryptographyFundamentals of cryptography
Fundamentals of cryptography
 
Cybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber SecurityCybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber Security
 
Mobile Forensics and Cybersecurity
Mobile Forensics and CybersecurityMobile Forensics and Cybersecurity
Mobile Forensics and Cybersecurity
 
Information security in todays world
Information security in todays worldInformation security in todays world
Information security in todays world
 

Viewers also liked

Information system security wk5-2-authentication
Information system security wk5-2-authenticationInformation system security wk5-2-authentication
Information system security wk5-2-authenticationBee Lalita
 
Information system security wk6-2
Information system security wk6-2Information system security wk6-2
Information system security wk6-2Bee Lalita
 
Information system security wk3-2
Information system security wk3-2Information system security wk3-2
Information system security wk3-2Bee Lalita
 
Information system security wk3-2
Information system security wk3-2Information system security wk3-2
Information system security wk3-2Bee Lalita
 
ความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูล
ความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูลความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูล
ความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูลtumetr1
 
Information system security wk6-1
Information system security wk6-1Information system security wk6-1
Information system security wk6-1Bee Lalita
 
Information system security wk5-1-pki
Information system security wk5-1-pkiInformation system security wk5-1-pki
Information system security wk5-1-pkiBee Lalita
 
Password hashing, salting, bycrpt
Password hashing, salting, bycrptPassword hashing, salting, bycrpt
Password hashing, salting, bycrptAhmad karawash
 
บทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่าย
บทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่ายบทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่าย
บทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่ายWanphen Wirojcharoenwong
 
บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์
บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์
บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์Wanphen Wirojcharoenwong
 

Viewers also liked (14)

Information system security wk5-2-authentication
Information system security wk5-2-authenticationInformation system security wk5-2-authentication
Information system security wk5-2-authentication
 
Information system security wk6-2
Information system security wk6-2Information system security wk6-2
Information system security wk6-2
 
Information system security wk3-2
Information system security wk3-2Information system security wk3-2
Information system security wk3-2
 
Security
SecuritySecurity
Security
 
Information system security wk3-2
Information system security wk3-2Information system security wk3-2
Information system security wk3-2
 
ความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูล
ความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูลความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูล
ความรู้พื้นฐานเกี่ยวกับการเข้ารหัสข้อมูล
 
Information system security wk6-1
Information system security wk6-1Information system security wk6-1
Information system security wk6-1
 
Information system security wk5-1-pki
Information system security wk5-1-pkiInformation system security wk5-1-pki
Information system security wk5-1-pki
 
Password hashing, salting, bycrpt
Password hashing, salting, bycrptPassword hashing, salting, bycrpt
Password hashing, salting, bycrpt
 
บทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่าย
บทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่ายบทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่าย
บทที่ 6 ความปลอดภัยบนระบบคอมพิวเตอร์และเครือข่าย
 
บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์
บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์
บทที่ 7 กฏหมายและจริยธรรมคอมพิวเตอร์
 
Secure hashing algorithm
Secure hashing algorithmSecure hashing algorithm
Secure hashing algorithm
 
Secure Hash Algorithm
Secure Hash AlgorithmSecure Hash Algorithm
Secure Hash Algorithm
 
บทที่8กฎหมายคอมพิวเตอร์[1]
บทที่8กฎหมายคอมพิวเตอร์[1]บทที่8กฎหมายคอมพิวเตอร์[1]
บทที่8กฎหมายคอมพิวเตอร์[1]
 

Similar to Information system security wk4-2

Similar to Information system security wk4-2 (7)

Information system security wk4-1
Information system security wk4-1Information system security wk4-1
Information system security wk4-1
 
Ch4
Ch4Ch4
Ch4
 
Chapter4
Chapter4Chapter4
Chapter4
 
Security
SecuritySecurity
Security
 
ระบบรักษาความปลอดภัยและชำระเงินสด
ระบบรักษาความปลอดภัยและชำระเงินสดระบบรักษาความปลอดภัยและชำระเงินสด
ระบบรักษาความปลอดภัยและชำระเงินสด
 
Chapter5
Chapter5Chapter5
Chapter5
 
Ch4
Ch4Ch4
Ch4
 

More from Bee Lalita

Information system security wk7-1-ids-ips
Information system security wk7-1-ids-ipsInformation system security wk7-1-ids-ips
Information system security wk7-1-ids-ipsBee Lalita
 
Information system security wk6-2
Information system security wk6-2Information system security wk6-2
Information system security wk6-2Bee Lalita
 
Information system security wk6-1
Information system security wk6-1Information system security wk6-1
Information system security wk6-1Bee Lalita
 
Information system security wk5-1-pki
Information system security wk5-1-pkiInformation system security wk5-1-pki
Information system security wk5-1-pkiBee Lalita
 
Information system security wk4-cryptography-2
Information system security wk4-cryptography-2Information system security wk4-cryptography-2
Information system security wk4-cryptography-2Bee Lalita
 
Information system security wk4-cryptography-2
Information system security wk4-cryptography-2Information system security wk4-cryptography-2
Information system security wk4-cryptography-2Bee Lalita
 
Information system security it346 wk4-1
Information system security it346 wk4-1Information system security it346 wk4-1
Information system security it346 wk4-1Bee Lalita
 
Information system security wk7-2-ids-ips_2
Information system security wk7-2-ids-ips_2Information system security wk7-2-ids-ips_2
Information system security wk7-2-ids-ips_2Bee Lalita
 
Information system security wk1-1
Information system security wk1-1Information system security wk1-1
Information system security wk1-1Bee Lalita
 
Information system security wk3-1
Information system security wk3-1Information system security wk3-1
Information system security wk3-1Bee Lalita
 

More from Bee Lalita (10)

Information system security wk7-1-ids-ips
Information system security wk7-1-ids-ipsInformation system security wk7-1-ids-ips
Information system security wk7-1-ids-ips
 
Information system security wk6-2
Information system security wk6-2Information system security wk6-2
Information system security wk6-2
 
Information system security wk6-1
Information system security wk6-1Information system security wk6-1
Information system security wk6-1
 
Information system security wk5-1-pki
Information system security wk5-1-pkiInformation system security wk5-1-pki
Information system security wk5-1-pki
 
Information system security wk4-cryptography-2
Information system security wk4-cryptography-2Information system security wk4-cryptography-2
Information system security wk4-cryptography-2
 
Information system security wk4-cryptography-2
Information system security wk4-cryptography-2Information system security wk4-cryptography-2
Information system security wk4-cryptography-2
 
Information system security it346 wk4-1
Information system security it346 wk4-1Information system security it346 wk4-1
Information system security it346 wk4-1
 
Information system security wk7-2-ids-ips_2
Information system security wk7-2-ids-ips_2Information system security wk7-2-ids-ips_2
Information system security wk7-2-ids-ips_2
 
Information system security wk1-1
Information system security wk1-1Information system security wk1-1
Information system security wk1-1
 
Information system security wk3-1
Information system security wk3-1Information system security wk3-1
Information system security wk3-1
 

Information system security wk4-2

  • 1. IT346 Information System Security Week 4-2: Hash Function & Digital Signature ผศ.ดร.มัชฌิกา อ่องแตง Faculty of Information Technology Page 1
  • 2. Cryptography Cryptography หมายถึงวิทยาการรหัสลับ มาจากคําว่า crypto ที่แปลว่า ซ่อน และคําว่า graph ที่แปลว่าการเขียนCryptography จึงมีความหมาย ว่า “การเขียนเพื่อซ่อนข้อมูล” Cryptography ใช้ในการป้องกันข้อมูลและสารสนเทศ โดยประกอบด้วย 3 เทคโนโลยีหลัก ‣ Symmetric Key Cryptography หรือ Secret Key Cryptographyคือการ เข้ารหัสข้อมูลแบบ “สมมาตร” ‣ Asymmetric Key Cryptography หรือ Public Key Cryptographyคือการ เข้ารหัสข้อมูลแบบ “อสมมาตร” ‣ Hash Function คือการสร้างตัวแทนข้อมูล Faculty of Information Technology Page 2
  • 3. Hash / Message Digest เมื่อต้องการรักษา Integrity (ความถูกต้องสมบูรณ์) ของข้อมูล เราใช้ เทคนิคการแปลงรูปแบบของข้อมูลที่รับเข้ามาให้เป็นข้อมูลที่ถูกย่อย (Message Digest) Message Digest ที่เรียกว่าเทคนิคการ Hash นําข้อมูลไปดําเนินการผ่าน One-Way Hash Function ซึ่งจะเปลี่ยน message ขนาดใหญ่ให้มีขนาดเล็ก และมีขนาดคงที่ไม่ว่า message ดั้งเดิม จะมีขนาดเท่าไรก็ตาม hm = h(m) เราไม่สามารถทํากระบวนการย้อนกลับเพื่อให้กลายเป็นข้อมูลต้นฉบับได้ แต่ เราสามารถใช้ Hash ในการตรวจสอบว่าข้อมูลที่ให้มาแต่ละครั้งตรงกับที่เรา ต้องการหรือไม่ หรือไฟล์นั้นมีการเปลี่ยนแปลงโดยคนอื่นหรือไวรัสหรือไม่ Faculty of Information Technology Page 3
  • 4. Hash / Message Digest คุณสมบัติของ One-Way Hash Function คือ ‣ เราไม่สามารถ (ในทางปฏิบัติ) คํานวณ message จาก hash ของมันได้ (One- Way) นั่นคือ หากมี h(m) เราไม่สามารถคํานวณหา m ได้ ‣ เราไม่สามารถ (ในทางปฏิบัติ) คํานวณหา message 2 อันที่มี hash ตรงกันได้ ‣ เราไม่สามารถ (ในทางปฏิบัติ) แก้ไข message โดยรักษาค่า hash ให้คงเดิมได้ ‣ สามารถคํานวณได้อย่างรวดเร็วและไม่ต้องใช้ทรัพยากรมาก ตัวอย่าง Hash Function ได้แก่ ‣ Message Digest (MD) เช่น MD-4, MD-5 ‣ Secure Hash Algorithm เช่น SHA-1, SHA-2 Faculty of Information Technology Page 4
  • 5. Hash Function ที่นิยม MD5 คิดค้นโดย Ron Rivest ซึ่งเป็น 1 ใน 3 คนที่คิดค้น RSA ‣ แม้ MD5 จะได้รับความนิยมอย่างมาก และได้มีการนํามาใช้แพร่หลายเช่น นํามาใช้สร้าง Digital Signature ในระบบ e-commerce อย่างไรก็ตาม MD5 ก็ถูก break ได้โดย Professor Dr. Xiaoyun Wang ในปี 2004 โดยใช้เครื่อง ซูเปอร์คอมพิวเตอร์ IBM P690 และใช้เวลา Crack 1 ชั่วโมงก็สามารถ break ได้ หลังจากนั้นก็มีคนอ้างว่าสามารถใช้เครือง Notebook ความเร็ว 1.6 GHz ่ เบรค MD5 ได้ภายในเวลา 8 ชั่วโมง SHA-0 และ SHA-1 ได้ถูกพัฒนาให้มีความแข็งแรงกว่า MD5 ‣ พัฒนาจาก MD5 เดิมให้ Output มีความเป็น Random สูงกว่า และมี Collision น้อยกว่าเพื่อลดโอกาสในการถูก Crack ได้ ‣ SHA0 และ SHA1 ก็ถูกเบรคได้โดย Professor Dr. Xiaoyun Wang เช่นกัน ‣ SHA2 ซึ่งยังไม่มีใคร break ได้ Faculty of Information Technology Page 5
  • 6. ตัวอย่าง 1: การใช้งาน Hash โดยปกติ เราใช้งาน Hash เพื่อตรวจสอบ Integrity ของข้อมูล ‣ Alice กับ Bob แชร์ Secret Key K ด้วยกัน ใช้ในการ Encrypt ข้อมูล ‣ Alice ส่งข้อมูล M ให้ Bob ดังนี้ • Encrypt ข้อมูล M ด้วย key K ได้เป็น EK(M) ทําเพื่อรักษา Security Goal ใด? • คํานวณ h(M) แล้วนําผลลัพธ์ที่ได้แนบไปกับ EK(M) ทําเพื่อรักษา Security Goal ใด? h(M) | EK(M) Bob Alice Note: Faculty of Information Technology F ˈ F Encrypt h(M)? Page 6
  • 7. ตัวอย่าง 1: การใช้งาน Hash ‣ Bob สามารถตรวจสอบ Integrity ของข้อมูลที่รับมาได้ ดังนี้ • Decrypt EK(M) ด้วย Key K เพื่อให้ได้ M • คํานวณ h(M) • เปรียบเทียบ h(M) ที่ตนคํานวณได้ กับ h(M) ที่ Alice แนบมา หากเท่ากัน แปลว่า ไม่ได้มีใครเปลี่ยนแปลง M h(M) | EK(M) Bob Alice h(M) | EK(M) Decrypt =? M hash h(M) Faculty of Information Technology Page 7
  • 8. ตัวอย่าง 2: การใช้งาน Hash ผู้ใช้ machigar ตั้ง password เป็นคําว่า abc123 ‣ หากเก็บรหัสผ่านลงบน Database โดยตรงจะทําให้ผู้ใดก็ตามที่เข้าถึงฐานข้อมูล ได้ ทราบรหัสผ่านที่เก็บไว้ (ผู้ที่เข้าถึงฐานข้อมูลได้เช่นผู้ดูแลระบบ ผู้ดูแล ฐานข้อมูล และแฮกเกอร์ที่อาจเจาะเข้ามาในระบบ เพื่อให้เก็บ password ได้อย่างปลอดภัย ระบบทําการสร้างตัวแทนรหัสผ่าน ด้วยฟังก์ชั่น Hash (สร้าง h(password)) ‣ ตัวอย่าง ใช้อลกอริธึม MD5 ย่อยรหัสผ่าน abc123 ได้เป็น ั h(abc123) = e99a18c428cb38d5f260853678922e03 ระบบเก็บ h(password) ลงใน Database แทนที่จะเก็บ password โดยตรง ทําให้การเปิดดูรหัสผ่านใน Database ไม่พบ password แต่จะพบ เพียงค่า h(password) ที่เก็บไว้แทน Faculty of Information Technology Page 8
  • 9. ตัวอย่าง 2: การใช้งาน Hash การเก็บ h(password) แทนค่า password เป็นการป้องกันการเปิดเผย password ‣ เราไม่สามารถใช้ค่า h(password) ในการคํานวณย้อนกลับไปเป็น password ได้ ในการตรวจสอบสิทธิ์ผู้ใช้แต่ละครั้งสําหรับการล็อกอินทําได้โดย ‣ นํา password ที่ผู้ใช้ป้อนเข้ามาไปผ่านฟังก์ชั่น Hash เพื่อคํานวณหา h(password) ‣ นําค่า h(password) ทื่ได้มาเทียบกับค่า h(password) ที่เก็บไว้ใน Database หากมีค่าตรงกันก็แสดงว่ารหัสผ่านถูกต้อง Faculty of Information Technology Page 9
  • 10. ตัวอย่างการใช้งาน Hash password password h(password) Password Database hash =? h(password) ˆ ก ก F Faculty of Information Technology F ก F Moodle F Linux ก F Fก ก F F F ก MD5 Web Application Mambo Page 10
  • 11. กิจกรรมที่ 1 จับคู่เพื่ออภิปรายกรณีการใช้เทคโนโลยี Cryptography เพื่อปกป้องการ สื่อสารต่อไปนี้ การสื่อสารนี้รักษา Confidentiality, Integrity หรือไม่ อย่างไร EK(M) Bob Alice การสื่อสารนี้รักษา Confidentiality, Integrity หรือไม่ อย่างไร M | h(M) Alice Faculty of Information Technology Bob Page 11
  • 12. กิจกรรมที่ 1 การสื่อสารรักษา Confidentiality, Integrity หรือไม่ อย่างไร h(M) | EK(M) Bob Alice การสื่อสารนี้รักษา Confidentiality, Integrity หรือไม่ อย่างไร EK(M | h(M)) Alice Faculty of Information Technology Bob Page 12
  • 13. Message Authentication Code (MAC) MAC คือการเข้ารหัสข้อมูลเพื่อใช้ในการพิสูจน์ความคงสภาพของข้อมูล โดยจะใช้ Secret Key และข้อความที่มีความยาวเท่าใดก็ได้ และคํานวณ ออกมาเป็น MAC ‣ การพิสูจน์ทราบข้อมูลนั้นผู้ตรวจสอบจะต้องมี Secret Key เดียวกัน เรา encrypt ค่า hash ของ message เพื่อสร้างเป็น message authentication code (MAC) ของ message จากนั้นจึงต่อส่วน MAC เข้าไปกับ message Faculty of Information Technology Page 13
  • 14. Message Authentication Code (MAC) กระบวนการสร้าง MAC Message M Hash Algorithm MAC Message M hash(M) Secret Key encryption MAC EK(h(M)) | M การใช้งาน MAC ในลักษณะนี้ รักษา Confidentiality หรือไม่? Faculty of Information Technology Page 14
  • 15. Message Authentication Code (MAC) กระบวนการตรวจสอบ MAC Message M MAC Secret Key decryption Hash Algorithm h(M) h(M) =? Faculty of Information Technology Page 15
  • 16. Asymmetric-Key Cryptography Asymmetric-key Cryptography เพื่อรักษา confidentiality ‣ Encrypt ข้อมูลที่ต้องการปกปิดด้วย public key ของผู้รบ ั Private Key Public Key Ciphertext Plaintext Plaintext Decryption Encryption E(P, PKreceiver) = C P = Plaintext C = Ciphertext PK = Public Key SK = Private Key D(C, SKreceiver) = P Asymmetric-key Cryptography เพื่อรักษา Non-Repudiation ‣ Encrypt ข้อมูลที่ต้องการยืนยันด้วย private key ของผูสง ้่ Public Key Private Key Plaintext Encryption E(P, SKsender) = C Faculty of Information Technology Ciphertext Decryption Plaintext D(C, PKsender) = P Page 16
  • 17. Digital Signatures การทําธุรกรรมอิเล็คทรอนิกส์จําเป็นที่จะต้องมีการยืนยันเอกสารหรือข้อมูลที่ ส่งว่าถูกส่งมาจากผู้ส่งจริง เพื่อการป้องกันการปฏิเสธการทําธุรกรรม (Nonrepudiation) และเป็นการพิสูจน์ทราบตัวตน (Authentication) ของ ผู้สร้างเอกสาร จาก Asymmetric Key Cryptography เราทราบว่าการเข้ารหัสข้อมูล ด้วย Private Key สามารถยืนยันผู้ส่งได้ ‣ เช่นผู้ใช้ A เข้ารหัสข้อมูลด้วย Private Key ของตนเองแล้วส่งข้อมูลไปให้ผู้ใช้ B และผู้ใช้ C จากนั้นผู้ใช้ B และผู้ใช้ C ก็ถอดรหัสโดยใช้ Public Key ของผู้ใช้ A ได้ เป็นการยืนยันได้ว่าข้อมูลมาจากผู้ใช้ A จริง เพราะเป็นคนเดียวที่มี Private Key ของผู้ใช้ A Faculty of Information Technology Page
  • 18. Digital Signature ลายเซ็นอิเล็กทรอนิกส์ (Digital Signature) อาศัย Asymmetric Key Cryptography เพื่อเป็นการรับรองว่าผู้ส่งนั้นเห็นด้วยกับข้อความที่ส่งและ ข้อความส่งถึงผู้รับโดยไม่มีการเปลี่ยนแปลงโดยบุคคลที่สาม เนื้อหาอาจจะ เปิดเผยได้ เทียบได้กับลายเซ็นกํากับการทําธุรกรรมบนกระดาษ Faculty of Information Technology Page 18
  • 19. Digital Signature นอกจากเราใช้ public-private key pair ในการรักษา confidentiality โดยการใช้ public key ในการ encrypt ข้อมูลแล้ว เรายังสามารถใช้ private key ในการ encrypt ข้อมูล เพื่อพิสูจน์ตัวตนของแหล่งที่มาของ ข้อมูลได้ (message authentication) ‣ เฉพาะผู้ส่งทีแท้จริงเท่านั้นทีสามารถ encrypt ข้อมูลได้ เนื่องจาก private key ่ ่ จะรู้เฉพาะผู้ส่งเท่านั้น เมื่อ encrypt ด้วย private key จะต้อง decrypt ด้วย public key ที่ สัมพันธ์กัน E(P, SKsender) = C Faculty of Information Technology E(C, PKsender) = P Page 19
  • 20. แนวคิดการทํา Enveloping เนื่องจาก symmetric key cryptography ใช้เวลาดําเนินการต่ํา จึงนิยม มากกว่าในการ encrypt ข้อมูลมากๆ เราสามารถใช้ public key encryption เป็นกลไกในการส่ง secret (symmetric) key ได้ Message m Ks Random Key Symmetric Encryption PKreceiver encryption E(Ks, PKreceiver) Faculty of Information Technology E(m, Ks) Page 20
  • 21. Enveloping ใน Digital Signature ในการส่งข้อมูลที่มีขนาดใหญ่ หากต้องการที่จะยืนยันผู้ส่งด้วยวิธีการข้างต้น เราจะต้องทําการเข้ารหัสข้อมูลทั้งหมดด้วย Private Key ของผู้ส่ง (เพื่อ เป็นการยืนยันตัวตนผู้ส่ง) ‣ ข้อเสียคือจะต้องมีการเข้ารหัสข้อมูลขนาดใหญ่ทงหมด และผู้รับจะต้องทําการ ั้ ถอดรหัสข้อมูลทั้งหมดเช่นกัน ซึ่งทําให้เปลือง CPU และเปลืองเวลาในการ ประมวลผล หากข้อมูลที่จะส่งนั้น "ไม่เป็นความลับ“ เราสามารถที่จะประยุกต์ใช้การทํา Enveloping ให้ใช้ CPU และเปลืองเวลาน้อยลงได้โดยใช้ฟังก์ชั่น Hash ‣ เนื่องจากข้อมูลไม่เป็นความลับ จึงไม่ทํา Secret Key Encryption แต่ทําการ hash แทน เพื่อให้ข้อมูลขนาดเล็กลง Faculty of Information Technology Page
  • 22. Enveloping ใน Digital Signature เนื่องจากการดําเนินการ public key cryptosystem มักใช้เวลาใน ดําเนินการสูง เราจึงนิยมทํา message authentication โดยการ encrypt ส่วน Message Authentication Code (MAC) ซึ่งมีขนาดเล็กว่า และ encrypt ได้รวดเร็วกว่าแทน เรียกว่า Digital Signature (DS) Message m Hash Algorithm DS Message m h(m) SKsender encryption DS Faculty of Information Technology SK = Private Key Page 22
  • 23. Digital Signature ขั้นตอนในการทํา Digital Signature ‣ ข้อมูลที่ต้องการจะส่งจะถูกคํานวณให้ได้ข้อความทีสั้นลงโดยใช้ Hash Function ่ ผลทีได้จะเป็นข้อมูลสั้นๆ และความยาวคงที่ ซึ่งเรียกว่า Message Digest ่ ‣ ผู้ส่งจะเซ็นชื่อในข้อความโดยการ Encrypt ตัว Message Digest h(m) โดยใช้ Private Key ของตัวเอง เรียกผลลัพธ์ดังกล่าวว่า Digital Signature ‣ ข้อความเดิมจะถูกส่งไปพร้อมกับ Digital Signature นี้ไปให้ผู้รับ ‣ ผู้รับทําการตรวจสอบข้อมูลทีได้รับ ่ DS = E(h(m), SKsender) Faculty of Information Technology Page 23
  • 24. Digital Signature ขั้นตอนในการตรวจสอบ Digital Signature DS Message m Hash Algorithm PKsender decryption h(m) h(m) =? Faculty of Information Technology Page 24
  • 25. Faculty of Information Technology Page 25
  • 27. กิจกรรมที่ 2 จับกลุ่ม กลุ่มละ 3 คน เพื่ออภิปรายความแตกต่างระหว่าง Message Integrity Code (MAC) และ Digital Signature ‣ การทํางานและโครงสร้างของ MAC และ Digital Signature ต่างกันอย่างไร ‣ ความแตกต่างดังกล่าวทําให้ MAC และ Digital Signature ให้คุณสมบัติด้าน การรักษาความมั่นคงปลอดภัยต่างกันอย่างไร Faculty of Information Technology Page 27