Cryptography Tutorials - Herong's Tutorial Examples - v5.42, by Herong Yang
Using SHA1 Message Digest in PHP
This section provides a tutorial example on how to use SHA1 message digest algorithm in PHP. The PHP engine has a built-in function sha1().
If you are interested in using SHA1 in PHP, you can use the built-in function sha1(). Here is a sample program showing you how to use sha1() function:
<?php # PhpSha1Test.php # Copyright (c) HerongYang.com. All Rights Reserved. # $input = ""; $output = sha1($input); print("\n"); print("SHA1(\"".$input."\") =\n"); print(" $output\n"); $input = "abc"; $output = sha1($input); print("\n"); print("SHA1(\"".$input."\") =\n"); print(" $output\n"); $input = "abcdefghijklmnopqrstuvwxyz"; $output = sha1($input); print("\n"); print("SHA1(\"".$input."\") =\n"); print(" $output\n"); ?>
If you run this sample program with PHP 5, you should get:
SHA1("") = da39a3ee5e6b4b0d3255bfef95601890afd80709 SHA1("abc") = a9993e364706816aba3e25717850c26c9cd0d89d SHA1("abcdefghijklmnopqrstuvwxyz") = 32d10c7b8cf96570ca04ce37f2a19d84240d3a89
The output matches the testing result listed in FreeBSD libmd makefile: http://www.opensource.apple.com/source/libmd/libmd-2/Makefile.
Table of Contents
Introduction to AES (Advanced Encryption Standard)
DES Algorithm - Illustrated with Java Programs
DES Algorithm Java Implementation
DES Algorithm - Java Implementation in JDK JCE
DES Encryption Operation Modes
PHP Implementation of DES - mcrypt
Blowfish - 8-Byte Block Cipher
Secret Key Generation and Management
Cipher - Secret Key Encryption and Decryption
RSA Implementation using java.math.BigInteger Class
Introduction of DSA (Digital Signature Algorithm)
Java Default Implementation of DSA
Private key and Public Key Pair Generation
PKCS#8/X.509 Private/Public Encoding Standards
Cipher - Public Key Encryption and Decryption
►SHA1 Mesasge Digest Algorithm
What Is SHA1 Message Digest Algorithm?
SHA1 Message Digest Algorithm Overview
Using SHA1 Message Digest in Java
►Using SHA1 Message Digest in PHP
Using SHA1 Message Digest in Perl
OpenSSL Introduction and Installation
OpenSSL Generating and Managing RSA Keys
OpenSSL Generating and Signing CSR
OpenSSL Validating Certificate Path
"keytool" and "keystore" from JDK
"OpenSSL" Signing CSR Generated by "keytool"
Migrating Keys from "keystore" to "OpenSSL" Key Files
Certificate X.509 Standard and DER/PEM Formats
Migrating Keys from "OpenSSL" Key Files to "keystore"