本文介绍了“块中没有DEK-Info头”当试图读取加密的私钥时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取一个加密的PKCS8私钥文件。我生成了这样的密钥:

  openssl genrsa -out file.pem -passout pass:file -aes256 1024 
openssl pkcs8 -topk8 -inform pem -in file.pem -outform pem -out filePKCS8.pem

我尝试以Go方式阅读它:

  block,_:= pem.Decode(key)
return x509 .DecryptPEMBlock(block,password)

但是我收到一个错误消息:

  x509:没有DEK-Info标题块在

但是,我无法弄清楚发生了什么问题。我是否生成了错误的关键字还是我使用了错误的库?



有没有人有任何想法?



你可以使用这个包:


I'm trying to read an encrypted PKCS8 private key file. I generated the keys like this:

openssl genrsa -out file.pem -passout pass:file -aes256 1024
openssl pkcs8 -topk8 -inform pem -in file.pem -outform pem -out filePKCS8.pem

And I try reading it in Go this way:

block, _ := pem.Decode(key)
return x509.DecryptPEMBlock(block, password)

But I get an error saying:

x509: no DEK-Info header in block

However, I can't figure out what's going wrong. Am I generating the key wrong or am I using the wrong library? I see libraries specifically for reading unencrypted PKCS8 files but none for encrypted PKCS8 files specifically.

Does anyone have any idea?

解决方案

Go don't have function to decrypt PKCS8 keys in standard library.

You can this package:https://github.com/youmark/pkcs8/blob/master/pkcs8.go#L103

这篇关于“块中没有DEK-Info头”当试图读取加密的私钥时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:42