我们可以在 PHP 中使用 .cer 格式的私钥进行加密吗?

发布于 2024-11-27 06:12:54 字数 168 浏览 1 评论 0原文

从 PHP 函数来看,

openssl_public_encrypt ( string $data , string &$crypted , mixed $key )

它仅适用于 $key 的 .pem 吗?或者我们可以使用.cer 或.crt?

From PHP function

openssl_public_encrypt ( string $data , string &$crypted , mixed $key )

does it work only with .pem for the $key? or we can use .cer or .crt?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-12-04 06:12:54

看来您的标题是错误的,因为 openssl_public_encrypt 使用公钥而不是私钥加密数据。但是,这里列出了 X.509 证书的常见文件扩展名:

.pem               (Privacy Enhanced Mail) Base64 encoded DER certificate
                   enclosed between "-----BEGIN CERTIFICATE-----" and
                   "-----END CERTIFICATE-----"

.cer, .crt, .der   usually in binary DER form, but Base64-encoded certificates are
                   common too (see .pem above)

.p7b, .p7c         PKCS#7 SignedData structure without data, just certificate(s)
                   or CRL(s)

.p12               PKCS#12, may contain certificate(s) (public) and private keys
                   (password protected)

.pfx               PFX, predecessor of PKCS#12 (usually contains data in PKCS#12
                   format, e.g., with PFX files generated in IIS)

It seems that your title is wrong because openssl_public_encrypt encrypts data with a public key, not with a private key. However, here is a list with common filename extensions for X.509 certificates are:

.pem               (Privacy Enhanced Mail) Base64 encoded DER certificate
                   enclosed between "-----BEGIN CERTIFICATE-----" and
                   "-----END CERTIFICATE-----"

.cer, .crt, .der   usually in binary DER form, but Base64-encoded certificates are
                   common too (see .pem above)

.p7b, .p7c         PKCS#7 SignedData structure without data, just certificate(s)
                   or CRL(s)

.p12               PKCS#12, may contain certificate(s) (public) and private keys
                   (password protected)

.pfx               PFX, predecessor of PKCS#12 (usually contains data in PKCS#12
                   format, e.g., with PFX files generated in IIS)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文