Ruby 相当于 php 函数 openssl_pkey_get_public
我有 php 脚本,其中密码编码使用 openssl:
$key = openssl_get_publickey($certificate);
openssl_public_encrypt($pass,$userPassCrypted,$key,OPENSSL_PKCS1_PADDING);
openssl_free_key($key);
做同样的事情
现在我尝试用 ruby require 'openssl' cert = OpenSSL::X509::Certificate.new(证书)
公钥 = cert.public_key
passwordSSL = public_key.public_encrypt(password, 1)
这里的问题是这些密码编码不匹配
证书相同但公钥 在 PHP 中是:
-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----
在 ruby 中是:
-----BEGIN RSA PUBLIC KEY----- ... -----END RSA PUBLIC KEY-----
我想这就是区别(密钥体也不一样)...
我怎样才能在 ruby 中获得与 PHP 中相同的公钥?或者是 可以通过某种方式转换 RSA 密钥吗?
或者也许我必须用另一种方式来做?
任何建议都将受到高度赞赏。
I have the php script where the password encoding done using the
openssl:
$key = openssl_get_publickey($certificate);
openssl_public_encrypt($pass,$userPassCrypted,$key,OPENSSL_PKCS1_PADDING);
openssl_free_key($key);
Now I trying to make the same with ruby
require 'openssl'
cert = OpenSSL::X509::Certificate.new(certificate)
public_key = cert.public_key
passwordSSL = public_key.public_encrypt(password, 1)
The problem here is that these password encoding isn't match
The certificate the same but the public key
in PHP is:
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
in ruby is:
-----BEGIN RSA PUBLIC KEY-----
...
-----END RSA PUBLIC KEY-----
I guess here is the difference (keys body also not the same)...
How can I get inside ruby the same public key as in PHP? Or is it
possible convert RSA key by somehow?
Or maybe I have to do it with another way?
Any suggestions highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下命令打开它:
希望这有帮助!
更新:啊,好的。是的,我认为没有办法从 OpenSSL 输出中删除“RSA”,而不用正则表达式删除它。
You can open this by using the following:
Hope this helps!
UPDATE: Ah, okay. Yeah, I don't think there is a way to remove the " RSA " from the OpenSSL output without removing it with a regular expression.