openSSL 生成 RSA 私有秘鑰密碼錯誤問題


Case

安裝openSSL,添加到環境變量

第一種方式,進入到openssl環境,然后執行命令

openssl
genrsa -des3 -passout pass:"123456" -out D:\test1.key

第二種方式,通過PowerShell調用openssl.exe執行命令

openssl genrsa -des3 -passout pass:"123456" -out D:\test2.key

Check

Check的時候會提示輸入密碼,我們均輸入:123456

Check test1.key:

openssl rsa -check -in D:\test1.key

輸出錯誤:unable to load Private Key

Check test2.key:

openssl rsa -check -in D:\test2.key

正常

Why

本質原因就是命令參數寫法有問題導致,-passout pass:"123456"應該寫成-passout "pass:123456"就不會有差異了。
第一種方式,進入openSSL環境,密碼就是pass:后的所有字符,包括特殊字符,所以密碼為:"123456"(包括引號)
第二種方式,PowerShell調用openSSL.exe,PowerShell會刪除-passout pass:"123456"中的引號,密碼為:123456

cmd和PowerShell調用其他exe時候參數中引號傳遞問題?

示例程序

cmd調用,可以看到,只是刪除了雙引號

PowerShell調用,單雙引號都被刪除

如果確實需要傳遞雙引號,那就轉義'\"',或者使用"""

ref

https://www.openssl.org/docs/manmaster/man1/openssl-passphrase-options.html
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.2#passing-arguments-that-contain-quote-characters


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM