cmd - windows cmd/Powershell如何在没有密码提示的情况下从私钥pfx文件中导出公钥?
问题描述
“从 pfx 导出证书”可以无缝进行,无需用户输入密码。
Powershell 6.1+ commandlet 允许-password
切换Get-PfxCertificate。
对于早期版本,可能的解决方案是:
powershell (Get-PfxCertificate -FilePath Private.pfx).GetPublicKey()
,用户必须在命令提示符下输入密码,否则会出错:
Get-PfxCertificate : The specified network password is not correct.
密码必须在提示时输入;不接受复制/粘贴。也没有为命令提供密码的开关。
解决方案
Get-Pfxdata
做同样的工作,允许在脚本中处理密码,而无需用户干预受密码保护的 pfx 文件:
set /p pwd="Enter password: "
pwdstring
set pwd=convertto-securestring \"%pwd%\" -asplaintext -force
powershell Export-Certificate -Cert ((Get-PfxData -FilePath Private.pfx -password (%pwd%)).EndEntityCertificates[0]) -FilePath Public.cer
在 Win 10 CMD 上测试
推荐阅读
- python - evalf 没有为代数表达式生成数值结果
- php - 如何从批处理文件启动 php 本地服务器?
- javascript - 是否可以将函数调用存储在动态变量中?
- powershell - 处理 powershell 工作流和循环中的错误
- spring-kafka - spring kafka消息处理遥测
- python - 使用 tweepy 同时收集多个用户的推文
- vba - 当我不尝试更新时记录集更新错误
- php - 我如何知道 PHP 中的两个日期是否在同一周?
- sql-server - 无法在 SQL Server 2019 数据库中创建数据库图
- html - 下载属性打开文件而不是下载