From 6274d5ff7d471093f8fa4c934a7674cbdee558fb Mon Sep 17 00:00:00 2001 From: Jozef Gajdos Date: Fri, 17 Mar 2023 12:14:18 +0100 Subject: Add suport of SubjectPublicKeyInfo in Org.BouncyCastle.OpenSsl.PemWriter --- crypto/src/openssl/MiscPemGenerator.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'crypto/src/openssl/MiscPemGenerator.cs') diff --git a/crypto/src/openssl/MiscPemGenerator.cs b/crypto/src/openssl/MiscPemGenerator.cs index fe2583063..cafbdedbb 100644 --- a/crypto/src/openssl/MiscPemGenerator.cs +++ b/crypto/src/openssl/MiscPemGenerator.cs @@ -99,6 +99,11 @@ namespace Org.BouncyCastle.OpenSsl encoding = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(akp).GetDerEncoded(); } } + else if (obj is SubjectPublicKeyInfo subjectPublicKeyInfo) + { + type = "PUBLIC KEY"; + encoding = subjectPublicKeyInfo.GetEncoded(); + } else if (obj is X509V2AttributeCertificate attrCert) { type = "ATTRIBUTE CERTIFICATE"; @@ -240,8 +245,8 @@ namespace Org.BouncyCastle.OpenSsl #endif private static byte[] EncodePrivateKey( - AsymmetricKeyParameter akp, - out string keyType) + AsymmetricKeyParameter akp, + out string keyType) { PrivateKeyInfo info = PrivateKeyInfoFactory.CreatePrivateKeyInfo(akp); AlgorithmIdentifier algID = info.PrivateKeyAlgorithm; @@ -253,7 +258,7 @@ namespace Org.BouncyCastle.OpenSsl DsaParameter p = DsaParameter.GetInstance(algID.Parameters); - BigInteger x = ((DsaPrivateKeyParameters) akp).X; + BigInteger x = ((DsaPrivateKeyParameters)akp).X; BigInteger y = p.G.ModPow(x, p.P); // TODO Create an ASN1 object somewhere for this? -- cgit 1.4.1