duai4379
2013-12-27 09:14
浏览 1.0k
已采纳

OpenSSL加密是可以的,但解密是错误的

first, im sorry for my bad English.

Im forced to use OpenSSL and im testing it now.

I have public key:

$key = "{key}"; 
$key = "-----BEGIN PUBLIC KEY-----
" . wordwrap($key, 64, "
", true) . "
-----END PUBLIC KEY-----";

When i use:

$secret = "test";
$test = openssl_public_encrypt($secret, $encrypted, $key);

... everything is ok, in $test is true - so encrypting is ok.

But now, i want decrypt it back, so i use:

$ok = openssl_public_decrypt($encrypted, $vys, $key);

...and on this place, the $ok variable contains false :( How it is possible?

Thanks very much to all!

图片转代码服务由CSDN问答提供 功能建议

首先,我很抱歉我的英语不好。

我被迫使用 OpenSSL现在正在测试它。

我有公钥:

  $ key =“{key}”;  
 $ key =“----- BEGIN PUBLIC KEY ----- 
”。  wordwrap($ key,64,“
”,true)。  “
 ----- END PUBLIC KEY -----”; 
   
 
 

当我使用时:

   $ secret =“test”; 
 $ test = openssl_public_encrypt($ secret,$ encrypted,$ key); 
   
 
 

...一切正常 ,$ test是真的 - 所以加密是可以的。

但现在,我想要将其解密,所以我使用:

   $ ok = openssl_public_decrypt($ encrypted,$ vys,$ key); 
   
 
 

...在这个地方,$ ok变量包含false:( How 有可能吗?

非常感谢所有人!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douwei1944 2013-12-27 10:18
    已采纳

    You should decrypt with openssl_private_decrypt()
    And you need to provide private key as argument.
    Try to read more about public key encryption and openssl_public_encrypt

    打赏 评论

相关推荐 更多相似问题