常见问题解决 --- Error outputting keys and certificates 84480000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto\evp\evp_fetch.c:386:Global default library context
Error outputting keys and certificates 84480000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto\evp\evp_fetch.c:386:Global default library context, Algorithm (RC2-40-CBC : 0), Properties () PS C:\Users\21558>
解决办法
以下是解决 OpenSSL 在 Windows 上因算法不兼容导致报错的详细步骤:
---
### **问题原因**
错误 `Algorithm (RC2-40-CBC : 0), Properties ()` 表明你的 PFX 文件使用了 **RC2-40-CBC** 这种旧加密算法,而 OpenSSL 3.x 默认禁用了此算法。需通过以下方法绕过限制:
---
### **解决方案 1:启用 OpenSSL 的遗留算法支持**
在提取命令中强制启用旧版算法兼容模式。
1. **提取证书**(已成功,无需修改):
```cmd
openssl pkcs12 -in your_cert.pfx -clcerts -nokeys -out cert.crt
```
2. **提取私钥时添加 `-legacy` 参数**:
```cmd
openssl pkcs12 -in your_cert.pfx -nocerts -out key.pem -nodes -legacy
```
- `-legacy`:启用对旧算法的支持(如 RC2)。
- 输入 PFX 密码后,应成功生成 `key.pem`。
---
### **解决方案 2:降级 OpenSSL 版本**
安装 OpenSSL 1.1.1(支持旧算法且无需额外参数)。
1. **下载 OpenSSL 1.1.1**:
- 访问 [Win32/Win64 OpenSSL 1.1.1 下载页](https://slproweb.com/products/Win32OpenSSL.html)。
- 选择 **1.1.1.x 版本**(如 `Win64 OpenSSL 1.1.1u`)。
2. **安装并替换系统路径**:
- 安装时勾选 `Copy OpenSSL DLLs to /bin directory` 和 `Add OpenSSL to system PATH`。
- 重启命令提示符后验证版本:
```cmd
openssl version
```
> 应显示 `OpenSSL 1.1.1u`。
3. **重新执行提取命令(无需 `-legacy`)**:
```cmd
openssl pkcs12 -in your_cert.pfx -nocerts -out key.pem -nodes
```
---
### **解决方案 3:重新生成 PFX 文件(推荐一劳永逸)**
如果拥有原始证书和私钥,重新生成 PFX 时使用现代加密算法(如 AES)。
1. **使用 OpenSSL 生成新 PFX**:
```cmd
openssl pkcs12 -export -in cert.crt -inkey key.pem -out new_cert.pfx -certpbe AES-256-CBC -keypbe AES-256-CBC -macalg sha256
```
- `-certpbe` 和 `-keypbe`:指定加密算法为 AES。
- `-macalg`:指定哈希算法为 SHA256。
2. **使用新 PFX 文件重新提取**:
```cmd
openssl pkcs12 -in new_cert.pfx -nocerts -out key.pem -nodes
```
---
### **配置 Nginx 的注意事项**
1. **私钥格式**:确保 `key.pem` 是 PEM 格式(以 `-----BEGIN PRIVATE KEY-----` 开头)。
2. **文件路径**:在 Nginx 配置中使用正斜杠 `/` 指定路径:
```nginx
ssl_certificate conf/ssl/fullchain.crt;
ssl_certificate_key conf/ssl/key.pem;
```
---
### **验证是否成功**
1. 检查私钥与证书是否匹配:
```cmd
openssl x509 -noout -modulus -in cert.crt | openssl md5
openssl rsa -noout -modulus -in key.pem | openssl md5
```
- 若两个哈希值相同,则匹配成功。
---
### **总结**
- **首选方案**:执行命令时添加 `-legacy` 参数(临时解决)。
- **长期方案**:重新生成 PFX 文件并弃用 RC2 算法。
- 确保 Nginx 配置指向正确的证书和私钥路径。
浙公网安备 33010602011771号