diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-07-30 17:32:16 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-07-30 17:32:16 +0700 |
commit | 85bcf2b23afe09aa68615f070e428384b3973b49 (patch) | |
tree | 337c9e264307bec35276b16ce7304c74ce6e82bd /crypto | |
parent | Allocate memory for SCrypt in 32KiB chunks (diff) | |
download | BouncyCastle.NET-ed25519-85bcf2b23afe09aa68615f070e428384b3973b49.tar.xz |
Add generic private key output to openssl
Diffstat (limited to '')
-rw-r--r-- | crypto/src/openssl/MiscPemGenerator.cs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/crypto/src/openssl/MiscPemGenerator.cs b/crypto/src/openssl/MiscPemGenerator.cs index 22ae1eae1..4237adf8f 100644 --- a/crypto/src/openssl/MiscPemGenerator.cs +++ b/crypto/src/openssl/MiscPemGenerator.cs @@ -97,10 +97,7 @@ namespace Org.BouncyCastle.OpenSsl AsymmetricKeyParameter akp = (AsymmetricKeyParameter) obj; if (akp.IsPrivate) { - string keyType; - encoding = EncodePrivateKey(akp, out keyType); - - type = keyType + " PRIVATE KEY"; + encoding = EncodePrivateKey(akp, out type); } else { @@ -174,10 +171,7 @@ namespace Org.BouncyCastle.OpenSsl AsymmetricKeyParameter akp = (AsymmetricKeyParameter) obj; if (akp.IsPrivate) { - string keyType; - keyData = EncodePrivateKey(akp, out keyType); - - type = keyType + " PRIVATE KEY"; + keyData = EncodePrivateKey(akp, out type); } } @@ -221,7 +215,7 @@ namespace Org.BouncyCastle.OpenSsl if (oid.Equals(X9ObjectIdentifiers.IdDsa)) { - keyType = "DSA"; + keyType = "DSA PRIVATE KEY"; DsaParameter p = DsaParameter.GetInstance(algID.Parameters); @@ -240,19 +234,23 @@ namespace Org.BouncyCastle.OpenSsl if (oid.Equals(PkcsObjectIdentifiers.RsaEncryption)) { - keyType = "RSA"; + keyType = "RSA PRIVATE KEY"; + + return info.ParsePrivateKey().GetEncoded(); } else if (oid.Equals(CryptoProObjectIdentifiers.GostR3410x2001) || oid.Equals(X9ObjectIdentifiers.IdECPublicKey)) { - keyType = "EC"; + keyType = "EC PRIVATE KEY"; + + return info.ParsePrivateKey().GetEncoded(); } else { - throw new ArgumentException("Cannot handle private key of type: " + Platform.GetTypeName(akp), "akp"); - } + keyType = "PRIVATE KEY"; - return info.ParsePrivateKey().GetEncoded(); + return info.GetEncoded(); + } } public PemObject Generate() |