php使用base64加密和解密
文章描述:
php使用base64加密和解密字符串
字符串
$str = 'http://www.baidu.com';
加密
echo $strBase64 = base64_encode($str);
aHR0cDovL3d3dy5iYWlkdS5jb20=
解密
echo $strx = base64_decode($strBase64);
http://www.baidu.com
另外
// 生成加密后的用户信息
$userinfo = array(
'username' => '123456',
'password' => 'ABCD1234'
);
$encrypted = base64_encode(serialize($userinfo));
print_r($encrypted);
YToyOntzOjg6InVzZXJuYW1lIjtzOjY6IjEyMzQ1NiI7czo4OiJwYXNzd29yZCI7czo4OiJBQkNEMTIzNCI7fQ==
// 解密用户信息
$userinfo = unserialize(base64_decode($encrypted));
print_r($userinfo);
Array ( [username] => 123456 [password] => ABCD1234 )
serialize() 函数用于序列化对象或数组,并返回一个字符串。
$sites = array('苹果', '香蕉', '榴莲');
$serialized_data = serialize($sites);
echo $serialized_data;
$unserialize_data = unserialize($serialized_data);
print_r($unserialize_data);
发布时间:2023/04/14
发表评论