ݺߣ

ݺߣShare a Scribd company logo
PHP7.2
Johney Park
Use Libsodium
TL; DR
?
?
Side Channel Attack
• , ( )
?
• , , , ,
, , ?
• 

Meltdown, Spectre
• Large Prime Number
Elliptic Curve Cryptography
•
• RSA 3072bit = ECC 256bit
• key
•
• Side Channel Attack
Authenticated Encryption
• Message Authentication Code
•
• (nonce)
•
Post-Quantum Cryptography
•
•
PHP 7.2 ?
Libsodium & Argon2
Libsodium
• NaCl(salt) (2008-2010)
• Networking and cryptography library, high-speed software library for
network communication, encryption, decryption, signature, etc.
• US EU Funding
• C(with inline assembler), C++, Python Wrapper
• Libsodium NaCl Cross-Platform (2013)
•
• 2017 PHP7.2
Argon2
• Side Channel Attack Hash Algorithm
• 2015
• password_hash Libsodium , Libsodium
password_hash BCRYPT . (
7.2 )
• password_hash Libsodium
• Libsodium
• hash
Argon2
$password = 'secret password';
$hash = password_hash($password, PASSWORD_ARGON2I);
echo $hash . PHP_EOL;
if (password_verify($password, $hash)) {
echo 'valid password' . PHP_EOL;
if(password_needs_rehash($hash, PASSWORD_ARGON2I)) {
echo 'save new password hash' . PHP_EOL;
}
} else {
echo 'invalid password!' . PHP_EOL;
}
$argon2i$v=19$m=1024,t=2,p=2$RWRRb01PMnRETU8zMXNrag$/
BKnBpq0Yl82OsimPaNn/SlnAuaGsYWi3H95bfZKFSc
valid password
Argon2
$password = 'secret password';
$hash = sodium_crypto_pwhash_str(
$password,
SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
echo $hash . PHP_EOL;
if (sodium_crypto_pwhash_str_verify($hash, $password)) {
sodium_memzero($password);
echo 'valid password' . PHP_EOL;
if (sodium_crypto_pwhash_str_needs_rehash($hash,
SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE)) {
echo 'save new password hash' . PHP_EOL;
}
} else {
sodium_memzero($password);
echo 'invalid password!' . PHP_EOL;
}
$argon2id$v=19$m=65536,t=2,p=1$zYnVgQGMf+YpTKZzTvqv2g$XHM3XJpOOgeQvibBX9fY4OB
6CA06aJVcsF+DmMFOMtc
valid password
Hash
• Rainbow table , Collision Attack
• Libsodium generic hash BLAKE2b
• short hash SipHash-2-4
• Libsodium
• PHP hash MD5 SHA-1
. SHA-256 SHA-512
Hash
$hash = sodium_bin2hex(sodium_crypto_generichash('message'));
echo $hash . PHP_EOL;
2e7836cc18ab1db2a2e239ebf4043772b3359520198b5fd55443b01a1023a5b0
$key = random_bytes(SODIUM_CRYPTO_SHORTHASH_KEYBYTES);
$hash = sodium_bin2hex(sodium_crypto_shorthash('message', $key));
echo $hash . PHP_EOL;
7b02d09fb8bd2289
$hash = hash('sha256', 'message');
echo $hash . PHP_EOL;
ab530a13e45914982b79f9b7e3fba994cfd1f3fb22f71cea1afbf02b460c6d1d
Secret Key
• XSalsa20
• Poly1305 MAC
• nonce
• AEAD AEAD
. ( ..)
Secret Key
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$key = random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
$message = 'secret message';
$cipher_text = sodium_bin2hex(sodium_crypto_secretbox($message, $nonce, $key));
sodium_memzero($message);
echo $cipher_text . PHP_EOL;
9bb7d572868a8ddb773398fd107b3ccbf8f6dd010809bb1f76008a4a2abc
$plain_text = sodium_crypto_secretbox_open(sodium_hex2bin($cipher_text), $nonce, $key);
echo $plain_text . PHP_EOL;
secret message
Public Key
• X25519 XSalsa20
• Poly1305 MAC
Public Key
$key_pair = sodium_crypto_box_keypair();
$public_key = sodium_crypto_box_publickey($key_pair);
$message = 'secret message';
$cipher_text = sodium_bin2hex(sodium_crypto_box_seal($message, $public_key));
sodium_memzero($message);
echo $cipher_text . PHP_EOL;
03fb2a60f2dbbe74c5f5eb2a9d13ea6a58c44badd2aa0963ff096c5b344bc5358a724badf814fa22c5566d
8b36867ddbf9ceb4fccbb77a3f303a037429ea
$plain_text = sodium_crypto_box_seal_open(sodium_hex2bin($cipher_text), $key_pair);
echo $plain_text . PHP_EOL;
secret message
Libsodium
7.1
Reference
• Official site

https://www.gitbook.com/book/jedisct1/
libsodium/details
• Paragon IE

https://paragonie.com/book/pecl-
libsodium
Ad

Recommended

Python Cryptography & Security
Python Cryptography & Security
Jose Manuel Ortega Candel
FIPS 140-2 Validations in a Secure Enclave
FIPS 140-2 Validations in a Secure Enclave
wolfSSL
Marco Balduzzi - Cyber-crime and attacks in the dark side of the web - Codemo...
Marco Balduzzi - Cyber-crime and attacks in the dark side of the web - Codemo...
Codemotion
" Breaking Extreme Networks WingOS: How to own millions of devices running on...
" Breaking Extreme Networks WingOS: How to own millions of devices running on...
PROIDEA
My Bro The ELK
My Bro The ELK
Tripwire
wolfSSL and TLS 1.3
wolfSSL and TLS 1.3
wolfSSL
Workshop on Wireless Security
Workshop on Wireless Security
amiable_indian
InfoSec World 2016 – RFIDiggity – Pentester Guide to Hacking HF/NFC and UHF...
InfoSec World 2016 – RFIDiggity – Pentester Guide to Hacking HF/NFC and UHF...
Bishop Fox
2016 TTL Security Gap Analysis with Kali Linux
2016 TTL Security Gap Analysis with Kali Linux
Jason Murray
osint + python: extracting information from tor network and darkweb
osint + python: extracting information from tor network and darkweb
Jose Manuel Ortega Candel
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Lane Huff
Rafa Sánchez & Fran Gomez - IoCker - When IPv6 met malware [rooted2019]
Rafa Sánchez & Fran Gomez - IoCker - When IPv6 met malware [rooted2019]
RootedCON
Fileextraction with suricata
Fileextraction with suricata
MrArora Arjuna
Hacking the Gateways
Hacking the Gateways
Onur Alanbel
Proofpoint Emerging Threats Suricata 5.0 Webinar
Proofpoint Emerging Threats Suricata 5.0 Webinar
Jason Williams
Dario Durando - IoT: Battle of Bots [rooted2018]
Dario Durando - IoT: Battle of Bots [rooted2018]
RootedCON
Kasza smashing the_jars
Kasza smashing the_jars
PacSecJP
DEF CON 27 - ROGER DINGLEDINE -tor censorship arms race
DEF CON 27 - ROGER DINGLEDINE -tor censorship arms race
Felipe Prado
[CB19] CIRCO: Cisco Implant Raspberry Controlled Operations by Emilio Couto
[CB19] CIRCO: Cisco Implant Raspberry Controlled Operations by Emilio Couto
CODE BLUE
BalCCon2k18 - Towards the perfect cryptocurrency wallet
BalCCon2k18 - Towards the perfect cryptocurrency wallet
Nemanja Nikodijević
DDoS Challenges in IPv6 environment
DDoS Challenges in IPv6 environment
Pavel Odintsov
RFID Hacking: Live Free or RFID Hard
RFID Hacking: Live Free or RFID Hard
Bishop Fox
The day I ruled the world (RootedCON 2020)
The day I ruled the world (RootedCON 2020)
Javier Junquera
proxy2: HTTPS pins and needles
proxy2: HTTPS pins and needles
inaz2
FastNetMon Advanced DDoS detection tool
FastNetMon Advanced DDoS detection tool
Pavel Odintsov
Penetration Testing Boot CAMP
Penetration Testing Boot CAMP
Shaikh Jamal Uddin l CISM, QRadar, Hack Card Recovery Expert
Pyongyang Fortress
Pyongyang Fortress
Mayank Dhiman
Kali Linux - Falconer
Kali Linux - Falconer
Tony Godfrey
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
Zend by Rogue Wave Software
Cryptography in PHP: Some Use Cases
Cryptography in PHP: Some Use Cases
Zend by Rogue Wave Software

More Related Content

What's hot (20)

2016 TTL Security Gap Analysis with Kali Linux
2016 TTL Security Gap Analysis with Kali Linux
Jason Murray
osint + python: extracting information from tor network and darkweb
osint + python: extracting information from tor network and darkweb
Jose Manuel Ortega Candel
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Lane Huff
Rafa Sánchez & Fran Gomez - IoCker - When IPv6 met malware [rooted2019]
Rafa Sánchez & Fran Gomez - IoCker - When IPv6 met malware [rooted2019]
RootedCON
Fileextraction with suricata
Fileextraction with suricata
MrArora Arjuna
Hacking the Gateways
Hacking the Gateways
Onur Alanbel
Proofpoint Emerging Threats Suricata 5.0 Webinar
Proofpoint Emerging Threats Suricata 5.0 Webinar
Jason Williams
Dario Durando - IoT: Battle of Bots [rooted2018]
Dario Durando - IoT: Battle of Bots [rooted2018]
RootedCON
Kasza smashing the_jars
Kasza smashing the_jars
PacSecJP
DEF CON 27 - ROGER DINGLEDINE -tor censorship arms race
DEF CON 27 - ROGER DINGLEDINE -tor censorship arms race
Felipe Prado
[CB19] CIRCO: Cisco Implant Raspberry Controlled Operations by Emilio Couto
[CB19] CIRCO: Cisco Implant Raspberry Controlled Operations by Emilio Couto
CODE BLUE
BalCCon2k18 - Towards the perfect cryptocurrency wallet
BalCCon2k18 - Towards the perfect cryptocurrency wallet
Nemanja Nikodijević
DDoS Challenges in IPv6 environment
DDoS Challenges in IPv6 environment
Pavel Odintsov
RFID Hacking: Live Free or RFID Hard
RFID Hacking: Live Free or RFID Hard
Bishop Fox
The day I ruled the world (RootedCON 2020)
The day I ruled the world (RootedCON 2020)
Javier Junquera
proxy2: HTTPS pins and needles
proxy2: HTTPS pins and needles
inaz2
FastNetMon Advanced DDoS detection tool
FastNetMon Advanced DDoS detection tool
Pavel Odintsov
Penetration Testing Boot CAMP
Penetration Testing Boot CAMP
Shaikh Jamal Uddin l CISM, QRadar, Hack Card Recovery Expert
Pyongyang Fortress
Pyongyang Fortress
Mayank Dhiman
Kali Linux - Falconer
Kali Linux - Falconer
Tony Godfrey
2016 TTL Security Gap Analysis with Kali Linux
2016 TTL Security Gap Analysis with Kali Linux
Jason Murray
osint + python: extracting information from tor network and darkweb
osint + python: extracting information from tor network and darkweb
Jose Manuel Ortega Candel
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Lane Huff
Rafa Sánchez & Fran Gomez - IoCker - When IPv6 met malware [rooted2019]
Rafa Sánchez & Fran Gomez - IoCker - When IPv6 met malware [rooted2019]
RootedCON
Fileextraction with suricata
Fileextraction with suricata
MrArora Arjuna
Proofpoint Emerging Threats Suricata 5.0 Webinar
Proofpoint Emerging Threats Suricata 5.0 Webinar
Jason Williams
Dario Durando - IoT: Battle of Bots [rooted2018]
Dario Durando - IoT: Battle of Bots [rooted2018]
RootedCON
Kasza smashing the_jars
Kasza smashing the_jars
PacSecJP
DEF CON 27 - ROGER DINGLEDINE -tor censorship arms race
DEF CON 27 - ROGER DINGLEDINE -tor censorship arms race
Felipe Prado
[CB19] CIRCO: Cisco Implant Raspberry Controlled Operations by Emilio Couto
[CB19] CIRCO: Cisco Implant Raspberry Controlled Operations by Emilio Couto
CODE BLUE
BalCCon2k18 - Towards the perfect cryptocurrency wallet
BalCCon2k18 - Towards the perfect cryptocurrency wallet
Nemanja Nikodijević
DDoS Challenges in IPv6 environment
DDoS Challenges in IPv6 environment
Pavel Odintsov
RFID Hacking: Live Free or RFID Hard
RFID Hacking: Live Free or RFID Hard
Bishop Fox
The day I ruled the world (RootedCON 2020)
The day I ruled the world (RootedCON 2020)
Javier Junquera
proxy2: HTTPS pins and needles
proxy2: HTTPS pins and needles
inaz2
FastNetMon Advanced DDoS detection tool
FastNetMon Advanced DDoS detection tool
Pavel Odintsov

Similar to PHP7.2와 모던 암호학 (9)

The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
Zend by Rogue Wave Software
Cryptography in PHP: Some Use Cases
Cryptography in PHP: Some Use Cases
Zend by Rogue Wave Software
Password Storage and Attacking in PHP
Password Storage and Attacking in PHP
Anthony Ferrara
Password Storage And Attacking In PHP - PHP Argentina
Password Storage And Attacking In PHP - PHP Argentina
Anthony Ferrara
Cryptography with Zend Framework
Cryptography with Zend Framework
Enrico Zimuel
Strong cryptography in PHP
Strong cryptography in PHP
Enrico Zimuel
Cryptography For The Average Developer
Cryptography For The Average Developer
Anthony Ferrara
Cryptography For The Average Developer - Sunshine PHP
Cryptography For The Average Developer - Sunshine PHP
Anthony Ferrara
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
Adam Englander
Password Storage and Attacking in PHP
Password Storage and Attacking in PHP
Anthony Ferrara
Password Storage And Attacking In PHP - PHP Argentina
Password Storage And Attacking In PHP - PHP Argentina
Anthony Ferrara
Cryptography with Zend Framework
Cryptography with Zend Framework
Enrico Zimuel
Strong cryptography in PHP
Strong cryptography in PHP
Enrico Zimuel
Cryptography For The Average Developer
Cryptography For The Average Developer
Anthony Ferrara
Cryptography For The Average Developer - Sunshine PHP
Cryptography For The Average Developer - Sunshine PHP
Anthony Ferrara
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
Adam Englander
Ad

Recently uploaded (20)

AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
Unit III_One Dimensional Consolidation theory
Unit III_One Dimensional Consolidation theory
saravananr808639
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
Machine Learning - Classification Algorithms
Machine Learning - Classification Algorithms
resming1
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
hosseinihamid192023
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
Structural Wonderers_new and ancient.pptx
Structural Wonderers_new and ancient.pptx
nikopapa113
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
Unit III_One Dimensional Consolidation theory
Unit III_One Dimensional Consolidation theory
saravananr808639
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
Machine Learning - Classification Algorithms
Machine Learning - Classification Algorithms
resming1
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
hosseinihamid192023
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
Structural Wonderers_new and ancient.pptx
Structural Wonderers_new and ancient.pptx
nikopapa113
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
Ad

PHP7.2와 모던 암호학

  • 3. ? ?
  • 4. Side Channel Attack • , ( ) ? • , , , , , , ? • 
 Meltdown, Spectre • Large Prime Number
  • 5. Elliptic Curve Cryptography • • RSA 3072bit = ECC 256bit • key • • Side Channel Attack
  • 6. Authenticated Encryption • Message Authentication Code • • (nonce) •
  • 9. Libsodium • NaCl(salt) (2008-2010) • Networking and cryptography library, high-speed software library for network communication, encryption, decryption, signature, etc. • US EU Funding • C(with inline assembler), C++, Python Wrapper • Libsodium NaCl Cross-Platform (2013) • • 2017 PHP7.2
  • 10. Argon2 • Side Channel Attack Hash Algorithm • 2015 • password_hash Libsodium , Libsodium password_hash BCRYPT . ( 7.2 ) • password_hash Libsodium • Libsodium • hash
  • 11. Argon2 $password = 'secret password'; $hash = password_hash($password, PASSWORD_ARGON2I); echo $hash . PHP_EOL; if (password_verify($password, $hash)) { echo 'valid password' . PHP_EOL; if(password_needs_rehash($hash, PASSWORD_ARGON2I)) { echo 'save new password hash' . PHP_EOL; } } else { echo 'invalid password!' . PHP_EOL; } $argon2i$v=19$m=1024,t=2,p=2$RWRRb01PMnRETU8zMXNrag$/ BKnBpq0Yl82OsimPaNn/SlnAuaGsYWi3H95bfZKFSc valid password
  • 12. Argon2 $password = 'secret password'; $hash = sodium_crypto_pwhash_str( $password, SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE ); echo $hash . PHP_EOL; if (sodium_crypto_pwhash_str_verify($hash, $password)) { sodium_memzero($password); echo 'valid password' . PHP_EOL; if (sodium_crypto_pwhash_str_needs_rehash($hash, SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE)) { echo 'save new password hash' . PHP_EOL; } } else { sodium_memzero($password); echo 'invalid password!' . PHP_EOL; } $argon2id$v=19$m=65536,t=2,p=1$zYnVgQGMf+YpTKZzTvqv2g$XHM3XJpOOgeQvibBX9fY4OB 6CA06aJVcsF+DmMFOMtc valid password
  • 13. Hash • Rainbow table , Collision Attack • Libsodium generic hash BLAKE2b • short hash SipHash-2-4 • Libsodium • PHP hash MD5 SHA-1 . SHA-256 SHA-512
  • 14. Hash $hash = sodium_bin2hex(sodium_crypto_generichash('message')); echo $hash . PHP_EOL; 2e7836cc18ab1db2a2e239ebf4043772b3359520198b5fd55443b01a1023a5b0 $key = random_bytes(SODIUM_CRYPTO_SHORTHASH_KEYBYTES); $hash = sodium_bin2hex(sodium_crypto_shorthash('message', $key)); echo $hash . PHP_EOL; 7b02d09fb8bd2289 $hash = hash('sha256', 'message'); echo $hash . PHP_EOL; ab530a13e45914982b79f9b7e3fba994cfd1f3fb22f71cea1afbf02b460c6d1d
  • 15. Secret Key • XSalsa20 • Poly1305 MAC • nonce • AEAD AEAD . ( ..)
  • 16. Secret Key $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); $key = random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES); $message = 'secret message'; $cipher_text = sodium_bin2hex(sodium_crypto_secretbox($message, $nonce, $key)); sodium_memzero($message); echo $cipher_text . PHP_EOL; 9bb7d572868a8ddb773398fd107b3ccbf8f6dd010809bb1f76008a4a2abc $plain_text = sodium_crypto_secretbox_open(sodium_hex2bin($cipher_text), $nonce, $key); echo $plain_text . PHP_EOL; secret message
  • 17. Public Key • X25519 XSalsa20 • Poly1305 MAC
  • 18. Public Key $key_pair = sodium_crypto_box_keypair(); $public_key = sodium_crypto_box_publickey($key_pair); $message = 'secret message'; $cipher_text = sodium_bin2hex(sodium_crypto_box_seal($message, $public_key)); sodium_memzero($message); echo $cipher_text . PHP_EOL; 03fb2a60f2dbbe74c5f5eb2a9d13ea6a58c44badd2aa0963ff096c5b344bc5358a724badf814fa22c5566d 8b36867ddbf9ceb4fccbb77a3f303a037429ea $plain_text = sodium_crypto_box_seal_open(sodium_hex2bin($cipher_text), $key_pair); echo $plain_text . PHP_EOL; secret message