Openssl的结果是不匹配的cmd和windows的电源外壳
问题描述:
现在我要获得android调试密钥的签名。Openssl的结果是不匹配的cmd和windows的电源外壳
在windows命令(cmd.exe的)
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl.exe sha1 -binary | openssl.exe base64
Enter keystore password: android
Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore debug.keystore -destkeystore debug.keystore -deststoretype pkcs12".
uQzK/Tk81BxWs8sBwQyvTLOWCKQ=
在windows电源外壳
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | .\openssl.exe
sha1 -binary | .\openssl.exe base64
Enter keystore password: android
Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore debug.keystore -destkeystore debug.keystore -deststoretype pkcs12".
Pz8/Pwo/MDNuPyE/Pys/Pz8/Sm8K
两个结果不匹配。
cmd.exe的:uQzK/Tk81BxWs8sBwQyvTLOWCKQ =
电源外壳:Pz8 /的Pwo/MDNuPyE/PYS/Pz8/Sm8K
为什么? 发生了什么?
答
这是PowerShell中对象管道的结果,您不应该在PowerShell中管道原始二进制数据,因为它会损坏。
在PowerShell中管理原始二进制数据永远不会安全。 PowerShell中的管道用于可以安全地自动转换为字符串数组的对象和文本。请详细阅读this了解详情。
用powershell计算的结果是错误的,因为您使用了管道。解决这个问题的方法之一是使用cmd.exe的从PowerShell中:写入输入/输出
cmd /C "keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl.exe sha1 -binary | openssl.exe base64"
而不是使用管道可以读/自/至文件。不幸的是,openssl.exe sha1没有-in
参数来指定输入文件。因此,我们需要使用PowerShell的命令行Start-Process
,它允许读取和处理参数-RedirectStandardInput
和-RedirectStandardOutput
写入文件:
keytool -exportcert -alias mykey -storepass wortwort -file f1.bin
Start-Process -FilePath openssl.exe -ArgumentList "sha1 -binary" -RedirectStandardInput f1.bin -RedirectStandardOutput f2.bin
Start-Process -FilePath openssl.exe -ArgumentList base64 -RedirectStandardInput f2.bin -RedirectStandardOutput o_with_ps.txt
keytool
写入到文件f1.bin
。然后openssl.exe sha1
从f1.bin
读取并写入f2.bin
。最后,从openssl.exe base64
读取f2.bin
和PowerShell的回购写入o_with-ps.txt
1此问题也被在[这个问题]长度讨论(https://github.com/PowerShell/PowerShell/issues/1908)。 –