如何PKCS8密钥文件转换成#C为DER格式? [英] How to convert pkcs8 key file to DER format in #C?
本文介绍了如何PKCS8密钥文件转换成#C为DER格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何转换PKCS8密钥文件DER格式,以获得XML格式的私钥和公钥
How to convert pkcs8 key file to DER format, to get Private and Public key in Xml format?
与OpenSSL的,我可以用做:
OpenSSL的PKCS8 -inform DER -in aaa010101aaa_FIEL.key退房手续aaa.txt到本地
with openssl I can do it using: openssl pkcs8 -inform DER -in aaa010101aaa_FIEL.key -out aaa.txt
aaa010101aaa_FIEL.key是bynary文件
aaa010101aaa_FIEL.key is bynary file
我试图用充气城堡库做,但我有问题,创造新的EncryptedPrivateKeyInfo(...
I'm trying to do it with Bouncy Castle library but I have problems to create new EncryptedPrivateKeyInfo(...
有一个职位做到这一点在Java中,但我需要它在C#
如何读取密码与Java加密密钥?
there is a post to do that in java, but i need it in c# How to read a password encrypted key with java?
推荐答案
我找到了答案!
byte[] dataKey = File.ReadAllBytes(fileName);
Org.BouncyCastle.Crypto.AsymmetricKeyParameter asp =
Org.BouncyCastle.Security.PrivateKeyFactory.DecryptKey(pass.ToCharArray(), dataKey);
MemoryStream ms = new MemoryStream();
TextWriter writer = new StreamWriter(ms);
System.IO.StringWriter stWrite = new System.IO.StringWriter();
Org.BouncyCastle.OpenSsl.PemWriter pmw = new PemWriter(stWrite);
pmw.WriteObject(asp);
stWrite.Close();
return stWrite.ToString();
这篇关于如何PKCS8密钥文件转换成#C为DER格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文