php openssl_digest example

by Anish

Posted on Wednesday December 12 , 2018


openssl_digest

openssl_digest: Computes a digest.

  • Supported PHP Versions (PHP 5 >= 5.3.0, PHP 7)

The Syntax

string openssl_digest ( string $data , string $method [, bool $raw_output = FALSE ] )
  • data: The data
  • Method The digest method to use, e.g. "sha256", see openssl_get_md_methods() for a list of available digest methods
  • Returns: The digest Value

Examples

openssl_digest() example Shows how to digest a given value

<?php  
/**  
 * Created by https://8gwifi.org  
 * User: Anish Nath  
 * Date: 2018-12-12 * Time: 11:46 
 * */  
$plaintext = "Hello 8gwifi.org";  
$digest = openssl_digest($plaintext, 'sha512');  
echo "SHA-512 Digest: $digest\n" ;  
  
$digest = openssl_digest($plaintext, 'sha');  
echo "SHA Digest: $digest\n" ;  
  
$digest = openssl_digest($plaintext, 'sha1');  
echo "SHA1 Digest: $digest\n" ;  
  
$digest = openssl_digest($plaintext, 'SHA224');  
echo "SHA-224 Digest: $digest\n" ;  
  
$digest = openssl_digest($plaintext, 'ripemd160');  
echo "ripemd160 Digest: $digest\n" ;  
  
$digest = openssl_digest($plaintext, 'MD5');  
echo "MD5 Digest: $digest\n" ;

The above example will output something similar to:

$ /usr/bin/php digest.php
SHA-512 Digest: 4f3fe637ab817caaeeccec2662afa312d2a23bf7c1218e8b54dcac005ff156242e33240bf2a66f5de6eee0f3b58b188abb8aca636eccb67a28dcd82a71ed6c2a
SHA Digest: 21cf6e105172354b7285787b84c3787e43c56ffe
SHA1 Digest: 5523bdf845330363e738519c87f5f0dafe72c051
SHA-224 Digest: 357b2b4194d0edc884337b77d43f92f85378f60c354cb5c745c63a4b
ripemd160 Digest: 839c924c99a21aec2bf6b7d04fe663509a406ff7
MD5 Digest: 5d567716bc513834a40ecf179fcab1ba

In openssl You can digest the given value using using openssl dgst option

$ echo -n  'Hello 8gwifi.org' | openssl dgst -sha512 -hex
4f3fe637ab817caaeeccec2662afa312d2a23bf7c1218e8b54dcac005ff156242e33240bf2a66f5de6eee0f3b58b188abb8aca636eccb67a28dcd82a71ed6c2a

$ echo -n  'Hello 8gwifi.org' | openssl dgst -sha1 -hex
5523bdf845330363e738519c87f5f0dafe72c051

$ echo -n  'Hello 8gwifi.org' | openssl dgst -ripemd160 -hex
839c924c99a21aec2bf6b7d04fe663509a406ff7

Thanku for reading !!! Give a Share for Support

Asking for donation sound bad to me, so i'm raising fund from The Modern Cryptography CookBook for Just $9. Leanpub books Discount coupon first 100 reader. No hurry read the sample chapters here then decide.

Alternatively to support you can buy My all four Cryptography book Just $10.99


Referefce
  • The Modern Cryptography Book.
  • Go lang Cryptography for developers
  • Python Cryptography
  • Cryptography for JavaScript Developer


python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers