HpkeDerivePrivateKey Method |
Derive an EC private key in a deterministic manner from input keying material using the DeriveKeyPair algorithm in RFC9180.
Namespace: CryptoSysPKIAssembly: diCrSysPKINet (in diCrSysPKINet.dll) Version: 23.0.0.30549 (23.1.0.0)
Syntaxpublic static string DerivePrivateKey(
byte[] ikm,
HpkeCurveName curveName,
HpkeOutputOpts opts = HpkeOutputOpts.Default
)
Public Shared Function DerivePrivateKey (
ikm As Byte(),
curveName As HpkeCurveName,
Optional opts As HpkeOutputOpts = HpkeOutputOpts.Default
) As String
Parameters
- ikm Byte
- Input key material (ikm).
This must have length in bytes at least as long as the key to be produced.
- curveName HpkeCurveName
- Curve name
- opts HpkeOutputOpts (Optional)
- Output options (default=internal key format)
Return Value
StringDerived private key in string form or an empty string on error.
RemarksBy default the key is output as an ephemeral "internal" key string,
which can be used directly with
Ecc.SaveKey,
Ecc.SaveEncKey,
Ecc.PublicKeyFromPrivate,
Ecc.DHSharedSecret and
Ecc.QueryKey.
If
opts is set to `OutputOpts.KeyAsHex` then the key is output in serialized hexadecimal form in the same manner
as the test vectors in [RFC9180] (without the clamping). The KDF to be used is fixed by the EC curve group as follows:
EC curve | KDF |
---|
P-256 | HKDF-SHA256 |
P-384 | HKDF-SHA384 |
P-521 | HKDF-SHA512 |
X25519 | HKDF-SHA256 |
X448 | HKDF-SHA512 |
Examplestring ikmhex = "7268600d403fce431561aef583ee1613527cff655c1343f29812e66706df3234";
string skhex = Hpke.DerivePrivateKey(Cnv.FromHex(ikmhex), Hpke.CurveName.X25519, Hpke.OutputOpts.KeyAsHex);
See Also