deno
08df1795 - fix(node/crypto): preserve binary key export passphrases (#36443)

Commit
30 days ago
fix(node/crypto): preserve binary key export passphrases (#36443) ## Summary - preserve normalized passphrase bytes when exporting encrypted private keys - normalize every accepted passphrase view to its exact byte range before native PEM and PKCS#8 DER export - add interoperability-style byte-range, legacy PEM, and validation coverage for Node-compatible passphrase types ## Details `KeyObject#export()` normalized passphrases to byte views but converted them to strings before calling native encryption. Binary inputs could therefore use different bytes than supplied. The native exporters now accept the normalized bytes directly. Passphrase parsing also converts accepted typed-array views to a byte-oriented `Uint8Array` using the backing buffer, byte offset, and byte length. This preserves non-UTF-8 data and offset view boundaries while ordinary string inputs remain UTF-8 encoded. The tests cover Buffer values containing non-UTF-8 bytes, Uint8Array, ArrayBuffer, offset DataView and typed-array views (`Int8Array`, `Uint16Array`, and `Float32Array`), and ordinary strings across PKCS#8 PEM and DER exports. Offset views are checked against independent exact-byte passphrases, and coverage also includes legacy SEC1 PEM encryption and invalid option behavior. ## Tests - `./tools/format.js --check` - `./tools/lint.js --js` - `cargo fmt --check` - `cargo check -p deno_node_crypto --features deno_core/v8` - `RUSTC_WRAPPER= cargo build --bin deno` - `./target/debug/deno test --config tests/config/deno.json --no-lock --unstable-net -A --parallel tests/unit_node/crypto/crypto_key_test.ts`
Author
Parents
Loading