0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cscの作法 その221

Last updated at Posted at 2022-07-01

概要

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");
		}
	}




以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?