更新——我用 Python 尝试了完全相同的东西,它完美地工作!
import os
os.system('certutil.exe -v -getkey "614D628A00000000014C" C:/Users/kra/kevin')
有人可以解释一下这个问题吗!
如果我运行这个红宝石代码:
require 'open3'
stdin, stdout, stderr = Open3.popen3('certutil -v -getkey "614D628A00000000014C" C:/Users/kra/kevin')
puts stdout.read
我收到以下错误:
Querying WIN-3CF41NBPT85.demo.com\demo-CA
CommonName: 614D628A00000000014C
CertUtil: -GetKey command FAILED: 0x80092004 (-2146885628)
CertUtil: Cannot find object or property.
但是,如果我直接从命令行运行命令,它就可以工作。
C:\Users\kra>certutil -getkey "614D628A00000000014C" C:/Users/kra/kevin
Querying WIN-3CF41NBPT85.cjndemo.com\cjndemo-CA.....................
"WIN-3CF41NBPT85.demo.com\demo-CA"
Serial Number: 614d628a00000000014c
Subject: CN=Kevin, C=GB
NotBefore: 11/30/2012 10:20 AM
NotAfter: 5/7/2013 9:29 AM
Template: Copy of Web Server
Version: 3
Cert Hash(sha1): 88 b1 7a 74 8c be 73 d5 16 07 7f 19 16 57 14 c5 dd a9 79 7f
Recipient Info[0]:
CMSG_KEY_TRANS_RECIPIENT(1)
CERT_ID_ISSUER_SERIAL_NUMBER(1)
Serial Number: 129e45d3000000000130
Issuer: CN=demo-CA, DC=demo, DC=com
Subject: CN=kra, CN=Users, DC=demo, DC=com
CertUtil: -GetKey command completed successfully.
有趣的是,如果我运行这个 ruby 代码:-
require 'open3'
stdin, stdout, stderr = Open3.popen3('certutil -recoverkey -p lexicon C:\Users\kra\kevin C:\Users\kra\kevin.pfx')
puts stdout.read
它也有效。
Computed Hash: 6e d3 b8 ad 93 16 7b f0 fb b3 f5 cd 7e e4 bb ad fb 95 a0 81
User Certificate:
Serial Number: 614d628a00000000014c
Issuer: CN=demo-CA, DC=demo, DC=com
Subject: CN=Kevin, C=GB
Cert Hash(sha1): 88 b1 7a 74 8c be 73 d5 16 07 7f 19 16 57 14 c5 dd a9 79 7f
CertUtil: -RecoverKey command completed successfully.
我假设它是某种奇怪的环境问题,因为显然 ruby 能够调用 certutil.exe 命令?