我想用pyjks加载一个包含可信证书的密钥库,我一直试图添加一个可信证书,从文件('trust2.pub')中读取。在
import jks
ks = jks.KeyStore.load('trustore_file.jks', 'trustore_pass')
new_entry = jks.TrustedCertEntry.new("trust2", open('trust2.pub', 'rb').read())
# Since I have not found an explicit way to add a new TrustedCertEntry,
# I thought this would work (add the 'new_entry' in the ks.entries dict).
ks.entries['trust2']=new_entry
# save the file with the new cert.
ks.save('trustore_file.jks', 'trustore_pass')
这实际上是用新条目保存jks文件,如果我尝试用给定的密码重新加载文件,就可以看到这个条目。但是当我尝试在ubuntu中使用keytool或在Windows中使用KeyStore Explorer打开它时,我得到了以下错误:
java.io.IOException: Short read of DER length
所以,也许这是我在jks文件中添加新的TrustedCertEntry的方式,但是我不知道,因为pyjks加载它没有问题。在
如果有人能帮忙的话,我会非常感激的。在
谢谢
我想出来了。导入.pub文件是我的错误。要导入的正确文件是一个X.509格式的.cer文件。如果其他人也犯同样的错误,我就把这个留在这里。在
相关问题 更多 >
编程相关推荐