【问题标题】:Porting php code that extracts public key from certificate and encrypt data to javascript移植从证书中提取公钥并将数据加密到javascript的php代码
【发布时间】:2022-01-17 08:56:06
【问题描述】:

我用 PHP 编写了这两个方法。 第一个方法 get_pubkey 从证书 (certnew.cer) 中提取公钥,第二个方法 encryptit(info) 使用第一个函数提取的公钥返回加密信息。 我需要将这 2 个函数移植到它们的 Javascript 等效函数。有人知道怎么做吗?

class Assdig 
{

   private $pubkey;

   /* (... )*/

   public function get_pubkey()
   {
       $certificado = __DIR__ . '/certnew.cer';

       $fp=fopen($certificado,"r"); 

       $this->pubkey=fread($fp,8192);

       fclose($fp);

       openssl_get_publickey($this->pubkey);
   }

   public function encryptit($info)
   {
     openssl_public_encrypt($info, $infoencrypted, $this->pubkey);

     return base64_encode($infoencrypted);
   }

}

【问题讨论】:

    标签: javascript php encryption


    【解决方案1】:

    我想你的意思是在本地机器或服务器上运行的 javascript 代码? (而不是在网络浏览器中)。

    有问题的 PHP 函数只是 openssl 库的包装器。我想最简单的方法是从您的 js 代码中执行 openssl 二进制文件。

    man openssl-pkey 列出了大部分相关命令

    【讨论】:

      猜你喜欢
      • 2011-08-12
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 2016-12-04
      • 2013-02-08
      相关资源
      最近更新 更多