当前位置:网站首页>Examples of AES and RSA encryption operations implemented by php7.1
Examples of AES and RSA encryption operations implemented by php7.1
2022-06-24 12:17:00 【PHP Development Engineer 】
This article gives an example of PHP7.1 Realized AES And RSA Encryption operation . Share with you for your reference , As follows :
AES:
<?php
header('Content-Type: text/plain;charset=utf-8');
$data = 'phpbest';
$key = 'oScGU3fj8m/tDCyvsbEhwI91M1FcwvQqWuFpPoDHlFk='; //echo base64_encode(openssl_random_pseudo_bytes(32));
$iv = 'w2wJCnctEG09danPPI7SxQ=='; //echo base64_encode(openssl_random_pseudo_bytes(16));
echo ' Content : '.$data."\n";
$encrypted = openssl_encrypt($data, 'aes-256-cbc', base64_decode($key), OPENSSL_RAW_DATA, base64_decode($iv));
echo ' encryption : '.base64_encode($encrypted)."\n";
$encrypted = base64_decode('To3QFfvGJNm84KbKG1PLzA==');
$decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', base64_decode($key), OPENSSL_RAW_DATA, base64_decode($iv));
echo ' Decrypt : '.$decrypted."\n";
?>use openssl Generate rsa Key pair ( Private key / Public key ):
openssl genrsa -out rsa_private_key.pem 2048 openssl rsa -pubout -in rsa_private_key.pem -out rsa_public_key.pem
RSA:
<?php
header('Content-Type: text/plain;charset=utf-8');
$data = 'phpbest';
echo ' Original content : '.$data."\n";
openssl_public_encrypt($data, $encrypted, file_get_contents(dirname(__FILE__).'/rsa_public_key.pem'));
echo ' Public key encryption : '.base64_encode($encrypted)."\n";
$encrypted = base64_decode('nMD7Yrx37U5AZRpXukingESUNYiSUHWThekrmRA0oD0=');
openssl_private_decrypt($encrypted, $decrypted, file_get_contents(dirname(__FILE__).'/rsa_private_key.pem'));
echo ' Private key decryption : '.$decrypted."\n";
?>PS: Interested friends about encryption and decryption can also refer to the online tools of this site :
On-line RSA encryption / Decryption tools :http://tools.jb51.net/password/rsa_encode
Text online encryption and decryption tool ( contain AES、DES、RC4 etc. ):http://tools.jb51.net/password/txt_encode
Online hash / Hash algorithm encryption tool :http://tools.jb51.net/password/hash_encrypt
On-line MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 encryption tool :http://tools.jb51.net/password/hash_md5_sha
On-line sha1/sha224/sha256/sha384/sha512 encryption tool :http://tools.jb51.net/password/sha_encode
Complete example :http://github.crmeb.net/u/defu
come from “ Open source world ” , link :https://ym.baisou.ltd/post/677.html, If you want to reprint , Please indicate the source , Otherwise, the legal liability will be investigated .
边栏推荐
- TP-LINK 1208 router tutorial (2)
- 【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
- 巧妙构思-铁死亡调节因子分型预后发6+
- 2021-06-03: Boolean operation. Given a Boolean expression and an expected cloth
- Linker --- linker
- 《梦华录》要大结局了,看超前点映不如先来学学它!
- 【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
- How to check the situation that the national standard platform easygbs equipment video cannot be accessed by grabbing packets?
- Why does the virtual machine Ping the host but not the virtual machine
- LS-DYNA新手入门经验
猜你喜欢

New progress in the construction of meituan's Flink based real-time data warehouse platform

u盘安装kali并且持久化

How to write controller layer code gracefully?

FreeRTOS overview and experience

我真傻,招了一堆只会“谷歌”的程序员!
Database migration tool flyway vs liquibase (II)

【数字IC/FPGA】Booth乘法器

Qt: judge whether the string is in numeric format

qt -- QTabWidget 中支持拖拽TabBar项

《梦华录》要大结局了,看超前点映不如先来学学它!
随机推荐
不用做实验的6分+基因家族纯生信思路~
Axi low power interface
深圳市人民医院程立新课题组提出多组学数据在肝细胞癌的诊断与预后分析的新方法meGPS
Libuv的安装及运行使用
Easynvr user login is modified to share the modification process of ip+ user name restriction
【老卫搞机】090期:键盘?主机?全功能键盘主机!
Realization of alarm clock with AHK
夜晚读书 -- 关于微服务和容器
怎么可以打新债 开户是安全的吗
How can I open an account with new bonds? Is it safe
《opencv学习笔记》-- 图像的载入和保存
Group planning - General Review
How does easygbs, a national standard platform, solve the problem that information cannot be carried across domains?
LS-DYNA新手入门经验
What are the low threshold financial products in 2022? Not much money
Opencv learning notes - loading and saving images
Influence of DEX optimization on arouter lookup path
单基因泛癌+简单实验就能发表7分+
怎样申购打新债 开户是安全的吗
ahk实现闹钟