Skip to main content

import_secret_key_jwk

Function import_secret_key_jwk 

Source
pub async fn import_secret_key_jwk(
    variant: EcdhVariant,
    jwk: String,
    options: AgreementKeyOptions,
) -> Result<SecretKey, Error>
Expand description

Import a static secret key as an EC private JWK (kty: "EC", with crv, d, and the public coordinates x/y, which RFC 7518 makes mandatory — this is inherently the public+private form). jwk is the JWK as JSON text; see mac-key.export-key-jwk for the package-wide JWK contract, including ext validation against the options’ extractability. d is the curve’s scalar and must lie in [1, n-1] (error.invalid-key otherwise).

Security:

  • Implementations MAY reject a JWK whose x/y is not the public point of d with error.invalid-key, and MUST NOT trust x/y for any operation: the imported key’s identity is d’s. (The W3C Web Cryptography API’s import steps do not mandate the consistency check, and engines differ, so a platform-backed host cannot promise it.)