0

So I am getting issues with creating a ECC Private Key then getting its Public Key in C# with Chilkat.

Chilkat Info Package: Dot Net Core DllDate: May 28 2021 ChilkatVersion: 9.5.0.87

Code

Chilkat.Ecc ecc = new Chilkat.Ecc();
Chilkat.Prng prng = new Chilkat.Prng();
string entropy = prng.GetEntropy(32, "base64");
prng.AddEntropy(entropy, "base64");

// Private Key created fine
Chilkat.PrivateKey privKey = ecc.GenEccKey("brainpoolP256r1", prng);

// Public key is created fine no indication of a problem
 var publicKey = privKey.GetPublicKey();

// Set up the verbose logging
publicKey.VerboseLogging = true;
publicKey.DebugLogFilePath = @"C:\Temp\Chilkat.log";

// Get the Pkcs8 Encoded Keys
var privPkcs8 = privKey.GetPkcs8ENC("base64");
var pubPkcs8 = publicKey.GetPkcs8ENC("base64");

// The private key Encoded String generates fine, but the public key is null.  
// Log follows code

Last Error Text:

ChilkatLog:
  KeySize:
    ChilkatVersion: 9.5.0.87
  --KeySize
--ChilkatLog

Debug Log

GetPkcs8ENC:
    DllDate: May 28 2021
    ChilkatVersion: 9.5.0.87
    UnlockPrefix: ******.*********
    Architecture: Little Endian; 64-bit
    VerboseLogging: 1
    toPubKeyDer:
        toPublicKeyDer:
            DecodeToAsn:
                null reference passed to BER decoder
                (leaveContext)
            (leaveContext)
        (leaveContext)
    Failed.
    (leaveContext)
KeySize:
    ChilkatVersion: 9.5.0.87
    (leaveContext)
KeySize:
    ChilkatVersion: 9.5.0.87
    (leaveContext)
KeySize:
    ChilkatVersion: 9.5.0.87
    (leaveContext 15ms)

One of the other things I found is it works for some curves but not others.

Results of tests
  "secp256r1": true,
  "secp384r1": true,
  "secp521r1": true,
  "secp256k1": true,
  "secp192r1": false,
  "secp224r1": false,
  "brainpoolP160r1": false,
  "brainpoolP192r1": false,
  "brainpoolP224r1": false,
  "brainpoolP256r1": false,
  "brainpoolP320r1": false,
  "brainpoolP384r1": false,
  "brainpoolP512r1": false

So it looks like only the NIST curves work? Which seems odd since I can use the Public key for key derivation.

Anyone have an idea what the issue might be (.Net Core limitation, Chilkat issue?)

Apricate anyone's thoughts.

2 Answers2

1

This was a bug and is now fixed. The fix will be in the next version (v9.5.0.88) released at the end of this month (August 2021). Updating to that version will solve the issue.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Chilkat Software
  • 1,405
  • 1
  • 9
  • 8
0

So I found an answer. Instead of exporting to Pkcs8 export to JWK and it works.

So change the GetPkcs8ENC to GetJwk and they work fine.

{
  "secp256r1": true,
  "secp384r1": true,
  "secp521r1": true,
  "secp256k1": true,
  "secp192r1": true,
  "secp224r1": true,
  "brainpoolP160r1": true,
  "brainpoolP192r1": true,
  "brainpoolP224r1": true,
  "brainpoolP256r1": true,
  "brainpoolP320r1": true,
  "brainpoolP384r1": true,
  "brainpoolP512r1": true
}

This is fine for me since I control the fetching of keys and can control the format. This may not work for everyone but it is a workaround if anyone else its this issue.