Home Backend Development PHP Problem How to encrypt php

How to encrypt php

Aug 30, 2019 am 10:12 AM
php encryption

How to encrypt php

MD5 encryption:

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

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 ] )
Copy after login

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作为第二个参数直接加入,
Copy after login

Sha1 encryption:

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

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
Copy after login

Urlencode encryption:

string urlencode ( string $str )
Copy after login

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;
  ?>
Copy after login

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 of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

CakePHP Useful Resources CakePHP Useful Resources Sep 10, 2024 pm 05:27 PM

The following resources contain additional information on CakePHP. Please use them to get more in-depth knowledge on this.

See all articles