• php opensll加解密类


     1 <?php
     2 
     3 $pri = "-----BEGIN RSA PRIVATE KEY-----
     4 MIICXQIBAAKBgQCzJc4RrAqaH2Es02XQ91Cqp/JK0yX893JQwFT2eAusnwQ90Bwu
     5 FQWdcZyKHP+I7XWMZc0qT/V/p51cq1d0OarPsuikth/43qP+1IWTYTv1i967pDnQ
     6 jXKbnm1dEMvjmS5hi7b/WwNfTi/VdAGLN0nxiHlX4+czjNHA3pCSQ9hCzwIDAQAB
     7 AoGAIF7aZ3MQz1yQMItaQHIPz2Zdb4vLt3P24gR+1bJHWb+6AnlSPjlqNFLNGF+5
     8 BMLzlJToh5a/I3vkAVSsjsHEzUl8OpbZm10toxH9UMpGd+2OdVYpceurRzIZ9/MF
     9 MuMBjv/+xukP4Nh8H6ekMGRMfoZtICAlj/kJxh7YlJlINfECQQDaarmknxzvw25k
    10 0SyLVsPffL3PQLHUZonFrwksGmk0XlTxgr+oUapi4SGVWuBkOjt7x4w8ktkiAtOZ
    11 tNtE3EALAkEA0flEzYg/cf170iUDtFEmWFLiBI8ajFC1rljaE4lFS67YCX+L1wnd
    12 5iQy29gV0qcxKme4bes+eUw+Jmeue0UuzQJBAJMJW/ZV4y4Jm4ylQF6BR5VxLXqT
    13 a+O4L7F0FzGoigBmLLr1MT8H0zODqY8ZQYxXo2m9uUuh9CiwTHDiTuZ5e2cCQGQ7
    14 3ylSUh8jR1mAy+znFCvznOtaOO0kliYdSjUrQUYot/6IwYOstR3ox9KEq548q863
    15 ZqYqN0+GIuEIe5Vi6D0CQQCp8fTMRCNtEAfRvYTV8PgxNE8pyIvntIeUT+MM+LGy
    16 4Xh2zYs7BiXeGx5mIT57QSYUsQKidYcneFyTl81oSgTQ
    17 -----END RSA PRIVATE KEY-----";
    18 
    19 
    20 $pub = "-----BEGIN PUBLIC KEY-----
    21 MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzJc4RrAqaH2Es02XQ91Cqp/JK
    22 0yX893JQwFT2eAusnwQ90BwuFQWdcZyKHP+I7XWMZc0qT/V/p51cq1d0OarPsuik
    23 th/43qP+1IWTYTv1i967pDnQjXKbnm1dEMvjmS5hi7b/WwNfTi/VdAGLN0nxiHlX
    24 4+czjNHA3pCSQ9hCzwIDAQAB
    25 -----END PUBLIC KEY-----";
    26 
    27  
    28 
    29 $rsa = new mycrypt($pub,$pri); 
    30 $encryptContent = $rsa -> encrypt('hankangkang'); 
    31 echo $encryptContent.'<br>';
    32 $decryptContent = $rsa -> decrypt($encryptContent);
    33 echo $decryptContent.'<br>';
    34 
    35 class mycrypt { 
    36 
    37 public $pubkey; 
    38 public $privkey; 
    39 
    40 function __construct($pub,$pri) { 
    41 $this->pubkey = $pub; 
    42 $this->privkey = $pri; 
    43 } 
    44 
    45 public function encrypt($data) { 
    46 if (openssl_public_encrypt($data, $encrypted, $this->pubkey)) 
    47 $data = base64_encode($encrypted); 
    48 else 
    49 throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?'); 
    50 
    51 return $data; 
    52 } 
    53 
    54 public function decrypt($data) { 
    55 if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey)) 
    56 $data = $decrypted; 
    57 else 
    58 $data = ''; 
    59 
    60 return $data; 
    61 } 
    62 
    63 }
  • 相关阅读:
    iOS 类知乎”分页”效果的实现?
    iOS 图解弹幕功能的实现
    iOS 为何使用runtime方法交换多次后却能按照交换顺序依次执行代码逻辑?
    iOS常用算法之单链表查找倒数第n个节点(图解)
    iOS常用算法之两个有序数组合并, 要求时间复杂度为0(n)
    iOS 常用算法之设计一个算法,验证某字符是否为合法IPV4字符
    iOS .Crash文件分析处理办法 (利用symbolicatecrash工具处理)
    iOS中UIWebview中网页宽度自适应的问题
    iOS开发
    安卓应用加固之反动态调试技术总结
  • 原文地址:https://www.cnblogs.com/hanyouchun/p/4642160.html
Copyright © 2020-2023  润新知