PHP opensll plus decryption class

Source: Internet
Author: User

<?php

$pri = "-----BEGIN RSA PRIVATE KEY-----
Miicxqibaakbgqczjc4rraqah2es02xq91cqp/jk0yx893jqwft2eausnwq90bwu
Fqwdczykhp+i7xwmzc0qt/v/p51cq1d0oarpsuikth/43qp+1iwtytv1i967pdnq
Jxkbnm1demvjms5hi7b/wwnfti/vdagln0nxihlx4+czjnha3pcsq9hczwidaqab
Aogaif7az3mqz1yqmitaqhipz2zdb4vlt3p24gr+1bjhwb+6anlspjlqnflngf+5
Bmlzljtoh5a/i3vkavssjshezul8opbzm10toxh9umpgd+2odvypceurrziz9/mf
mumbjv/+xukp4nh8h6ekmgrmfozticalj/kjxh7yljlinfecqqdaarmknxzvw25k
0sylvspffl3pqlhuzonfrwksgmk0xltxgr+ouapi4sgvwubkojt7x4w8ktkiatoz
Tnte3ealakea0flezyg/cf170iudtfemwflibi8ajfc1rljae4lfs67ycx+l1wnd
5iqy29gv0qcxkme4bes+euw+jmeue0uuzqjbajmjw/zv4y4jm4ylqf6br5vxlxqt
A+o4l7f0fzgoigbmllr1mt8h0zodqy8zqyxxo2m9uuuh9ciwthdituz5e2ccqgq7
3ylsuh8jr1may+znfcvznotaoo0kliydsjurquyot/6iwyostr3ox9keq548q863
Zqyqn0+giueie5vi6d0cqqcp8ftmrcnteafrvytv8pgxne8pyivntieut+mm+lgy
4xh2zys7bixegx5mit57qsyusqkidycnefytl81osgtq
-----END RSA PRIVATE KEY-----";


$pub = "-----BEGIN public KEY-----
Migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqczjc4rraqah2es02xq91cqp/jk
0yx893jqwft2eausnwq90bwufqwdczykhp+i7xwmzc0qt/v/p51cq1d0oarpsuik
Th/43qp+1iwtytv1i967pdnqjxkbnm1demvjms5hi7b/wwnfti/vdagln0nxihlx
4+czjnha3pcsq9hczwidaqab
-----END Public KEY-----";

$rsa = new Mycrypt ($pub, $PRI);
$encryptContent = $rsa Encrypt (' Hankangkang ');
echo $encryptContent. ' <br> ';
$decryptContent = $rsa-Decrypt ($encryptContent);
echo $decryptContent. ' <br> ';

Class Mycrypt {

Public $pubkey;
Public $privkey;

function __construct ($pub, $pri) {
$this->pubkey = $pub;
$this->privkey = $pri;
}

Public function Encrypt ($data) {
if (Openssl_public_encrypt ($data, $encrypted, $this->pubkey))
$data = Base64_encode ($encrypted);
Else
throw new Exception (' Unable to encrypt data. Perhaps it is bigger than the key size? ');

return $data;
}

Public function Decrypt ($data) {
if (Openssl_private_decrypt (Base64_decode ($data), $decrypted, $this->privkey))
$data = $decrypted;
Else
$data = ";

return $data;
}

}

PHP opensll plus decryption class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.