PHP双向加密用法

本文概述

通过使用此概念, 我们可以对数据进行编码和解码。简单来说, 双向加密意味着同时存在加密和解密功能。在PHP中, 双向加密是通过以下函数完成的。

  1. base64_encode()
  2. base64_decode()

1. base64_encode()

此函数用于使用base64编码给定数据。此功能在PHP 4.0中引入。

句法

string base64_encode ( string $data )

参数

Parameter Description 是强制性的
data 要编码的数据。 compulsory

退货

base64_encode()函数将编码后的数据作为字符串返回。

例子1

<?php
	$str= "srcmini";
	$str1= base64_encode($str);
	echo $str1;
?>

输出

PHP双向加密用法

例子2

<?php
	$str = 'Welcome to srcmini';
	echo base64_encode($str);
?>

输出

PHP双向加密用法

2. base64_decode()

base64_decode()函数用于解码base64编码的数据。此功能在PHP 4.0中引入。

句法

string base64_decode ( string $data [, bool $strict = FALSE ] )

参数

Parameter Description 是强制性的
data 编码数据。 compulsory
strict 如果strict参数设置为TRUE, 则如果输入包含来自base64字母外部的字符, 则base64_decode()函数将返回FALSE。 Optional

退货

base64_decode()函数返回解码后的数据, 否则返回false。返回的数据可以是二进制的。

例子1

<?php
	$str = 'V2VsY29tZSB0byBqYXZhdHBvaW50';
	echo base64_decode($str);
?>

输出

PHP双向加密用法

例子2

<?php
	$str= "amF2YXRwb2ludA==";
	$str1= base64_decode($str);
	echo $str1;
?>

输出

PHP双向加密用法

来源:

https://www.srcmini02.com/29409.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37944.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?