TechnitiumSoftware/DnsServer · error · ArgumentException
The ECDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ?
Error message
The ECDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ? "KSK" : "ZSK")}) private key must have key size of 384 bits. What it means
Thrown by DnssecPrivateKey.Create (PEM overload) for DnssecAlgorithm.ECDSAP384SHA384 when the imported ECDsa key's KeySize is not exactly 384 bits. As with the P-256 case, the curve fixes the size and any mismatch indicates a PEM for a different curve.
Source
Thrown at DnsServerCore/Dns/Dnssec/DnssecPrivateKey.cs:255
case DnssecAlgorithm.ECDSAP256SHA256:
using (ECDsa ecdsa = ECDsa.Create())
{
ecdsa.ImportFromPem(pemPrivateKey);
if (ecdsa.KeySize != 256)
throw new ArgumentException($"The ECDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ? "KSK" : "ZSK")}) private key must have key size of 256 bits.", nameof(pemPrivateKey));
return new DnssecEcdsaPrivateKey(algorithm, keyType, ecdsa.ExportParameters(true));
}
case DnssecAlgorithm.ECDSAP384SHA384:
using (ECDsa ecdsa = ECDsa.Create())
{
ecdsa.ImportFromPem(pemPrivateKey);
if (ecdsa.KeySize != 384)
throw new ArgumentException($"The ECDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ? "KSK" : "ZSK")}) private key must have key size of 384 bits.", nameof(pemPrivateKey));
return new DnssecEcdsaPrivateKey(algorithm, keyType, ecdsa.ExportParameters(true));
}
case DnssecAlgorithm.ED25519:
using (PemReader pemReader = new PemReader(new StringReader(pemPrivateKey)))
{
if (pemReader.ReadObject() is not Ed25519PrivateKeyParameters privateKey)
throw new ArgumentException($"The EdDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ? "KSK" : "ZSK")}) private key must be for Ed25519 curve.", nameof(pemPrivateKey));
return new DnssecEddsaPrivateKey(keyType, privateKey);
}
case DnssecAlgorithm.ED448:
using (PemReader pemReader = new PemReader(new StringReader(pemPrivateKey)))
{
if (pemReader.ReadObject() is not Ed448PrivateKeyParameters privateKey)
throw new ArgumentException($"The EdDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ? "KSK" : "ZSK")}) private key must be for Ed448 curve.", nameof(pemPrivateKey));View on GitHub (pinned to d0484b6c1e)
Solutions
- Regenerate a P-384 key: openssl ecparam -name secp384r1 -genkey -noout -out key.pem.
- If the PEM is genuinely P-256, use DnssecAlgorithm.ECDSAP256SHA256 instead.
- Align the DnssecAlgorithm with the PEM's curve.
Example fix
// before: pem is a P-256 key var key = DnssecPrivateKey.Create(DnssecAlgorithm.ECDSAP384SHA384, kt, p256Pem); // throws // after var key = DnssecPrivateKey.Create(DnssecAlgorithm.ECDSAP256SHA256, kt, p256Pem);
Defensive patterns
Strategy: validation
Validate before calling
using var ecdsa = ECDsa.Create();
ecdsa.ImportFromPem(pem);
if (ecdsa.KeySize != 384)
throw new InvalidOperationException($"ECDSA key is {ecdsa.KeySize} bits; ECDSAP384SHA384 requires 384 (P-384).");
var key = DnssecPrivateKey.Create(DnssecAlgorithm.ECDSAP384SHA384, keyType, pem); Type guard
static bool PemIsP384(string pem)
{
try { using var e = ECDsa.Create(); e.ImportFromPem(pem); return e.KeySize == 384; }
catch { return false; }
} Try / catch
try { return DnssecPrivateKey.Create(DnssecAlgorithm.ECDSAP384SHA384, keyType, pem); }
catch (ArgumentException ex) when (ex.ParamName == nameof(pem))
{ throw new InvalidOperationException("PEM is not a P-384 key; check the curve or use ECDSAP256SHA256.", ex); } Prevention
- Generate keys on secp384r1 for the P-384 algorithm.
- Keep the DnssecAlgorithm and the PEM curve in lockstep.
- Name key files by curve to prevent cross-use.
When it happens
Trigger: Calling Create(ECDSAP384SHA384, keyType, pem) where the PEM decodes to a non-P-384 EC key (e.g. P-256).
Common situations: Using a P-256 PEM with the P-384 algorithm; mislabeling key files during rotation.
Related errors
- The ECDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ?
- Valid RSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ?
- The EdDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ?
- The EdDSA ({(keyType == DnssecPrivateKeyType.KeySigningKey ?
- DNSSEC algorithm is not supported: {algorithm}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/5b2f5afcc083323a.
Report an issue: GitHub.