如何在mono中使用certmgr导入自签名证书的私钥

如何在mono中使用certmgr导入自签名证书的私钥,mono,openssl,x509certificate2,certificate-store,Mono,Openssl,X509certificate2,Certificate Store,我面临无法使用内置工具certmgr将证书私钥导入monos certificatestore/keypairstore的问题 将证书公共版本添加到存储中可以使用 user@maschine:~certs$ certmgr -add -c My MyCert.crt Mono Certificate Manager - version 2.10.8.1 Manage X.509 certificates and CRL from stores. Copyright 2002, 2003 Motu

我面临无法使用内置工具
certmgr
将证书私钥导入monos certificatestore/keypairstore的问题

将证书公共版本添加到存储中可以使用

user@maschine:~certs$ certmgr -add -c My MyCert.crt
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

1 certificate(s) added to store My.
但是,尝试添加相应的私钥会导致异常

user@maschine:~certs$ certmgr -add -c My MyCert.p12
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.


Unhandled Exception: System.Security.Cryptography.CryptographicException: Invalid MAC - file may have been tampered!
尝试先添加公用Verison(
.cer
),然后从专用版本(
.p12
)导入相应的私钥失败,但出现错误 稍有不同的例外:

user@maschine:~certs$ certmgr -add -c My MyCert.crt
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

1 certificate(s) added to store My.
user@maschine:~certs$ certmgr -importKey -c My MyCert.p12
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Unhandled Exception: System.Security.Cryptography.CryptographicException: Improperly protected user's key pairs in '/var/licapp/.config/.mono/keypairs'.
使用密码保护证书(并将相应的参数添加到命令中)也没有帮助

我在Debian哮喘病上使用mono V 2.10.8.1。有人知道如何在存储中添加句柄证书,并使用certmgr处理它们的密钥对吗

我正在考虑一种解决方法,我只将p12文件保存在我的应用程序下,而不使用存储,我想这将是一个更不干净的解决方案。但我无法将证书和密钥对同时添加到存储中


顺便说一句,证书似乎还可以。将它们添加到Windows下的存储中效果很好。

文档中存在一些问题,并且该工具的行为在某些地方有点奇怪或错误

  • 当 程序创建它们
    chmod 700~/.config/.mono/keypairs
    已解决列出的异常
  • 当您使用
    -importKey
    操作时,您仍然可以 必须指定对象类型证书,即使手册页 并不是说你必须使用对象类型。此外,也没有任何问题 “私钥”对象类型,但使用“证书”对象 键入(
    -c
    )。例如,
    certmgr-importKey-c-v-p P12密码My
    CertAndKeyPair.p12
    为我生成一条成功消息
  • 在步骤2之后,证书/密钥将保持不可访问状态。导入P12后,导入DER编码的证书。例如,
    certmgr-add-c My Certificate.cer
    这将使证书/密钥可用于您的.NET代码
  • 如果要将证书/密钥安装到计算机存储(
    -m
    ),则必须使用
    sudo

  • 谢谢,我终于可以使用步骤2中的命令导入我的pfx了。即使我的证书没有设置密码,它仍然需要指定
    -p”“
    ,才能工作。我认为这是旧版本mono(我运行的是4.2.1)中的一个bug,请参见此处的讨论: