当前位置:网站首页>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 .
边栏推荐
- Reading at night -- about microservices and containers
- QT -- the qtabwidget supports dragging tabbar items
- Which commercial insurance endowment insurance is good? Ranking of commercial endowment insurance products in 2022
- Cloud native database: the outlet of the database, you can also take off
- 10 zeros of D
- 《opencv学习笔记》-- 离散傅里叶变换
- 工具及方法 - 在Source Insight中使用代码格式化工具
- Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 1)
- Jenkins remote publishing products
- How to purchase new bonds is it safe to open an account
猜你喜欢

计组-总复习

Libuv的安装及运行使用
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

电商红包雨是如何实现的?拿去面试用(典型高并发)

AXI低功耗接口

我真傻,招了一堆只会“谷歌”的程序员!

Group planning - General Review

《opencv学习笔记》-- 分离颜色通道、多通道混合

How can a shell script (.Sh file) not automatically close or flash back after execution?
[Architect (Part 41)] installation of server development and connection to redis database
随机推荐
广发证券靠谱吗?开证券账户安全吗?
GTest从入门到入门
How to calculate the bandwidth of video transmission? How much bandwidth is required to transmit 4K video?
Deep learning ~11+ a new perspective on disease-related miRNA research
[redisson] analysis of semaphore lock source code
最新热点:使用铜死亡相关基因进行肿瘤预后分型!
About the unsupported instruction set SSE 4.2 of CPU in virtualization
Chenglixin research group of Shenzhen People's hospital proposed a new method of multi group data in the diagnosis and prognosis analysis of hepatocellular carcinoma megps
"Meng Hua Lu" is about to have a grand finale. It's better to learn it first than to look ahead!
Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!
A fault record of misoperation dhclient script
Reading at night -- about microservices and containers
How to open a new bond? Is it safe to open an account
How does wechat and QQ chat work? So simple!!!
Turn 2D photos into 3D models to see NVIDIA's new AI "magic"!
Coinbase将推出首个针对零售交易员的加密衍生产品
How to purchase new bonds is it safe to open an account
LS-DYNA新手入门经验
不用做实验的6分+基因家族纯生信思路~
How to develop hospital information system (his) with SMS notification and voice function