Skip to main content

encode

Function encode 

Source
pub fn encode(key: &Sm2PrivateKey) -> Vec<u8>
Expand description

Encode an SM2 private key as a DER-encoded unencrypted PKCS#8 OneAsymmetricKey.

The inner ECPrivateKey carries the scalar plus the optional publicKey field (uncompressed 04 || X || Y); the outer privateKeyAlgorithm is id-ecPublicKey with sm2p256v1.

The intermediate ECPrivateKey body is zeroized before return. The returned Vec<u8> contains the raw scalar bytes — caller is responsible for wiping it before letting it leave their stack frame.