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

时间:2011-07-30 14:44:07

标签: php cryptography openssl public-key-encryption

来自PHP功能

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

只有.pem才能使用$ key吗?或者我们可以使用.cer或.crt?

1 个答案:

答案 0 :(得分:2)

似乎您的标题错误,因为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)