当前位置:网站首页>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 .
边栏推荐
- Opencv learning notes - cv:: mat class
- How to calculate the bandwidth of video transmission? How much bandwidth is required to transmit 4K video?
- 哪个商业保险养老险好?2022年商业养老保险产品排名
- Is GF Securities reliable? Is it safe to open a securities account?
- Cloud native database: the outlet of the database, you can also take off
- How to purchase new bonds is it safe to open an account
- 巧妙构思-铁死亡调节因子分型预后发6+
- [live review] battle code pioneer phase 7: how third-party application developers contribute to open source
- 《opencv学习笔记》-- 感兴趣区域(ROI)、图像混合
- Database migration tool flyway vs liquibase (II)
猜你喜欢

FreeRTOS概述与体验

Install Kali on the U disk and persist it

How can a shell script (.Sh file) not automatically close or flash back after execution?

ArrayList # sublist these four holes, you get caught accidentally

AXI低功耗接口
[Architect (Part 41)] installation of server development and connection to redis database

Installation and operation of libuv

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

TP-LINK 1208 router tutorial (2)

《opencv学习笔记》-- 图像的载入和保存
随机推荐
Linker --- linker
Audio knowledge (III) -- MFCCs code implementation
How can I open an account with new bonds? Is it safe
How to develop hospital information system (his) with SMS notification and voice function
A fault record of misoperation dhclient script
Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 1)
Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
11+! Methylation modification patterns based on m6A regulatory factors in colon cancer are characterized by different tumor microenvironment immune spectra
"Meng Hua Lu" is about to have a grand finale. It's better to learn it first than to look ahead!
How to check the situation that the national standard platform easygbs equipment video cannot be accessed by grabbing packets?
基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
巧妙构思-铁死亡调节因子分型预后发6+
[Architect (Part 41)] installation of server development and connection to redis database
程序员大部分时间不是写代码,而是。。。
Popular science of data annotation: ten common image annotation methods
ArrayList # sublist these four holes, you get caught accidentally
Database migration tool flyway vs liquibase (II)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
GTest从入门到入门