Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect PEM format for ECGOST3410 PrivateKey #584

Open
heggi opened this issue Dec 17, 2024 · 0 comments
Open

[BUG] Incorrect PEM format for ECGOST3410 PrivateKey #584

heggi opened this issue Dec 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@heggi
Copy link

heggi commented Dec 17, 2024

Describe the Bug

The saved private key cannot be read by library and not correctly parsed by asn1 parsers

To Reproduce

var generator = GeneratorUtilities.GetKeyPairGenerator("ECGOST3410");
generator.Init(new ECKeyGenerationParameters(CryptoProObjectIdentifiers.GostR3410x2001CryptoProB, new SecureRandom()));
var gostKeyPair = generator.GenerateKeyPair();

using var writer = new StringWriter();
using var pemWriter = new PemWriter(writer);
pemWriter.WriteObject(keyPair.Private);
pemWriter.Writer.Flush();
var pem = writer.ToString(); 
// ^^^ Here PEM with `EC PRIVATE KEY` header, but can't correctly decoded by asn1 parsers (such as https://lapo.it/asn1js)

using var pemReader = new PemReader(new StringReader(pem));
var pemObj = pemReader.ReadObject() as AsymmetricKeyParameter ; 
// ^^^ Here got error
// Org.BouncyCastle.OpenSsl.PemException : problem creating EC private key: System.NullReferenceException: Object reference not set to an instance of an object.

Expected Behavior

Create PEM with PRIVATE KEY header (as it do openssl)
Read saved PEM back to AsymmetricKeyParameter

Product Deployment

Please complete the following information:

  • Version [2.5.0]

Desktop

Please complete the following information:

  • OS: Windows 10

Additional Context

@heggi heggi added the bug Something isn't working label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant