search

How to encrypt php

Aug 30, 2019 am 10:12 AM
phpencryption

How to encrypt php

MD5 encryption:

string md5 ( string $str [, bool $raw_output = false ] )

1.md5() returns the hash value as a 32-character hexadecimal number by default, It accepts two parameters, the first is the string to be encrypted, and the second is the Boolean value of raw_output. The default is false. If set to true, md5() will return the original 16-bit binary format message digest.

2.md5() is a one-way encryption and does not have a reverse decryption algorithm, but it can still crack some common strings through collection, enumeration, collision and other methods.

Related recommendations: "PHP Tutorial"

  $username='jellybool';
  $password='abcd';
  /*简单地对字符串进行md5加密*/
  echo md5($username);
  echo "
";
  echo md5($password);
  echo "
";
  /*更推荐的做法是对重要的敏感数据进行多次加密,以防被轻易破解*/
  echo md5(md5($password));
  /*以上输出:
  username:4f5436e5d72608fb647b691e8edcf42e
  password:7bf02cf0f4af6da4accbc73d2a175476
  password(两次加密):864704bb35754f8cd0232cba6b91521b
  string crypt ( string $str [, string $salt ] )

1.crypt() accepts two parameters, the first is the string that needs to be encrypted, and the second The second is the salt value (which is the encryption interference value, if not provided, it is automatically generated by PHP by default); returns a hashed string or a string of less than 13 characters, the latter is to distinguish the salt value.

2.crypt() is one-way encryption, the same as md5.

  $password='jellybool.com';
  echo crypt($password);
  echo "
";
  echo crypt($password,"jellybool");
  //输出:je7fNiu1KNaEs
  /*当我们要加自定义的盐值时,如例子中的jellybool作为第二个参数直接加入,

Sha1 encryption:

string sha1 ( string $str [, bool $raw_output = false ]

1. It is very similar to md5, except that sha1() returns a 40-character hash value by default , the properties of the incoming parameters are the same, the first one is the encrypted string, the second one is the Boolean value of raw_output, the default is false, if set to true, sha1() will return the original 20-bit original format message digest.

2.sha1() is also one-way encryption and has no reverse decryption algorithm.

  $my_intro="abc";
  echo sha1($my_intro);
  //输出:c98885c04c1208fd4d0b1dadd3bd2a9ff4d042ca
  echo "
";
  //当然,可以将多种加密算法混合使用
  echo md5(sha1($my_intro));
  //输出:94f25bf9214f88b1ef065a3f9b5d9874

Urlencode encryption:

string urlencode ( string $str )

1. One parameter, pass in the string to be encrypted (usually used to encrypt URLs).

2. urlencode is two-way encryption and can be encrypted with urldecode (strictly speaking, it is not a real encryption).

3. Return a string. All non-alphanumeric characters in this string except -_. will be replaced with a percent sign (%) followed by two hexadecimal digits. , spaces are encoded as plus signs ( ).

  $a = "http abc你好";
  $b = urlencode($a);
  $c = urldecode($b);
  echo $b;
  echo '
';
  echo $c;
  ?>

The above is the detailed content of How to encrypt php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor