概要
cscの作法、調べてみた。
秘密鍵pemファイルを、秘密鍵xmlファイルに変換してみた。
サンプルコード
pem2xml
using System;
using System.IO;
using System.Security.Cryptography;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Crypto.Operators;
using Org.BouncyCastle.Security;
using System.Collections.Generic;
using System.Text;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Prng;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Pkcs;
class test0 {
static void Main() {
AsymmetricCipherKeyPair privateKey;
using (var reader = new StreamReader(@"privatekey.pem", Encoding.ASCII))
{
var pemReader = new PemReader(reader);
privateKey = (AsymmetricCipherKeyPair) pemReader.ReadObject();
}
var rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters) privateKey.Private);
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
csp.ImportParameters(rsaParams);
File.WriteAllText("privatekey0.xml", csp.ToXmlString(true));
Console.WriteLine("ok");
}
}
以上。