简体   繁体   English

将使用GnuPG生成的RSA专用密钥导入C#

[英]Importing a private RSA key generated with GnuPG into C#

I want to sign some things within my C# application, but I need to do so with a private RSA key that I have previously generated with GnuPG instead of one new key generated within the application itself. 我想在我的C#应用​​程序中签名某些东西,但是我需要使用以前使用GnuPG生成的私有RSA密钥签名,而不是在应用程序本身内部生成一个新密钥。

I can export the RSA key with GnuPG and get something like (please, note I have omitted most lines here, is just an example): 我可以使用GnuPG导出RSA密钥,并得到类似的信息(请注意,我在这里省略了大多数行,仅是示例):

-----BEGIN PGP PRIVATE KEY BLOCK-----
lQOYBFXlhWwBCACfOGAw5Qr5ddFvDFZlDmys18KRV3XawArMiPe4hzivsEB3h+M1
df12Pz3l6IWnUJ/nJt/ZohwCOjm93+zT3xmGcAL9mh/lez6+UoQB8uB0hJ1ltLnZ
8RumvpExXJ2c6LfmaLrwyLHLUSAu8mfV6KoLtD9OxHkIdHktKpBzIPkLG9lRNAmN
kzjI9sz7pLq80+YevPA60niI0SBwbmJTHluvEQB32BkcEQ==
=u3H/
-----END PGP PRIVATE KEY BLOCK-----

Now the question is: how I could import that into C# cryptography subsystem so I can use it for signing things? 现在的问题是:如何将其导入C#加密子系统,以便可以将其用于签名?

The built-in crypto-library of C# only supports X.509, not OpenPGP; C#的内置加密库仅支持X.509,不支持OpenPGP。 both are incompatible although principally using the same cryptographic algorithms. 两者虽然主要使用相同的加密算法,但却不兼容。 You might be able to extract the RSA primes and import them somehow, but the libraries will still not be able to produce valid OpenPGP output. 您也许可以提取RSA素数并以某种方式导入它们,但是库仍将无法产生有效的OpenPGP输出。

Use the Bouncy Castle library instead, which is an OpenPGP implementation for C# (or interface GnuPG , for example through GPGME , but the C# binding is still an alpha version). 请使用Bouncy Castle库 ,它是C#的OpenPGP实现(或接口GnuPG ,例如通过GPGME ,但是C#绑定仍然是Alpha版本)。

What you quoted is not exactly an "RSA key" but an armored OpenPGP private key which probably includes RSA key material and also includes other stuff. 您所引用的并非完全是“ RSA密钥”,而是装甲的OpenPGP专用密钥,它可能包含RSA密钥材料,还包含其他内容。

As said in the other answer, you will have hard time importing it into C# (especially in Unity) without a third-party library. 如另一个答案中所述,您将很难在没有第三方库的情况下将其导入C#(尤其是在Unity中)。 If you need this as a one-time operation, you can take our SecureBlackbox (evaluation will be enough), load the OpenPGP key, then take the key material and save it to format which you can load to Unity later. 如果您需要一次性操作,则可以使用我们的SecureBlackbox(评估就足够了),加载OpenPGP密钥,然后获取密钥材料并将其保存为格式,以便以后加载到Unity中。

If you plan to perform such operations on a regular basis, it makes sense to write key generator in C# and generate RSA keys suitable for your needs without OpenPGP. 如果您计划定期执行此类操作,则可以在不使用OpenPGP的情况下,用C#编写密钥生成器并生成适合您需求的RSA密钥是有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM