Example of one way hash encryption operation implemented by PHP

  • 2021-09-12 00:44:42
  • OfStack

This paper describes the one-way hash encryption operation implemented by PHP. Share it for your reference, as follows:

Step 1 Encrypt files


<?php
//sha1_en.php
header("content-type:text/html;charset=utf-8");
$str = " I'm Zhang 3 Can I have some personal data ";
$salt="123456";// I am the only 1 Constant salt
$sha1=sha1($str.$salt);// Or $sha1=md5($str.$salt);
echo $str;
echo "<br/>";
echo $sha1;
echo "<br/>";
echo "http://localhost//sha1_de.php?str=$str&sha1=$sha1";
?>

Step 2 Decrypt files


<?php
//sha1_de.php
header("content-type:text/html;charset=utf-8");
$str=$_GET["str"];
$sha1=$_GET["sha1"];
$salt="123456";// I am the only 1 Constant salt
$verify=sha1($str.$salt);// Or $verify=md5($str.$salt);
echo $verify;
if($verify==$sha1){
  echo " You are Zhang 3 Give you information ";
}else{
  echo " You are a fake and shoddy product ";
  echo " Yours ip".$_SERVER['REMOTE_ADDR']." It has been recorded ";
}
?>

PS: Friends who are interested in encryption and decryption can also refer to the online tools of this site:

Text online encryption and decryption tools (including AES, DES, RC4, etc.):
http://tools.ofstack.com/password/txt_encode

MD5 Online Encryption Tool:
http://tools.ofstack.com/password/CreateMD5Password

Online hash/hash algorithm encryption tool:
http://tools.ofstack.com/password/hash_encrypt

Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 Encryption Tool:
http://tools.ofstack.com/password/hash_md5_sha

Online sha1/sha224/sha256/sha384/sha512 Encryption Tool:
http://tools.ofstack.com/password/sha_encode

For more readers interested in PHP related contents, please check the special topics of this site: "Summary of php Encryption Methods", "Summary of PHP Encoding and Transcoding Operation Skills", "Summary of PHP Mathematical Operation Skills", "Encyclopedia of PHP Array (Array) Operation Skills", "Summary of php String (string) Usage", "Tutorial of PHP Data Structure and Algorithm", "Summary of php Programming Algorithm" and "Summary of php Regular Expression Usage"

I hope this article is helpful to everyone's PHP programming.


Related articles: