验证 PKCS#12 文件的密码

Wae*_*_al 5 encryption openssl certificate pkcs#12

在我的 php 程序中,我尝试使用以下OpenSSL命令验证PKCS#12文件 (.p12/.pfx)的密码:

openssl pkcs12 -info -in myDigitalID.p12 -noout -passin pass:mypassword
Run Code Online (Sandbox Code Playgroud)

输出:

MAC: sha1, Iteration 2048
MAC length: 20, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
Error outputting keys and certificates
C4500000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto\evp\evp_fetch.c:349:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么它不起作用!请问有人可以帮忙吗?谢谢

小智 7

如果该命令用于以前的 OpenSSL 版本,请尝试以下操作

失败的命令:

openssl pkcs12 -info -in myDigitalID.p12 -noout -passin pass:mypassword
Run Code Online (Sandbox Code Playgroud)

失败命令输出:

MAC: sha1, Iteration 2000
MAC length: 20, salt length: 8
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2000
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2000
Error outputting keys and certificates
0C670000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto\evp\evp_fetch.c:349:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
Run Code Online (Sandbox Code Playgroud)

确保您拥有旧版库(名为legacy*.的文件,例如legacy-x64.dll)。与配置环境变量相比,将库复制为遗留版本可能更容易。(例如legacy.dll)位于库路径和包含openssl 可执行文件的路径中。

然后尝试命令:

openssl pkcs12 -info -in myDigitalID.p12 -noout -passin pass:mypassword -legacy -provider-path "C:\path\to\legacy_dir" -provider default
Run Code Online (Sandbox Code Playgroud)

这次它应该可以工作并显示如下内容:

MAC: sha1, Iteration 2000
MAC length: 20, salt length: 8
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2000
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2000
Certificate bag
Run Code Online (Sandbox Code Playgroud)

  • openssl 帮助说:“-legacy 使用旧版加密:3DES_CBC 用于密钥,RC2_CBC 用于证书” (2认同)