Skip to main content

Module pkcs8

Module pkcs8 

Source
Expand description

PKCS#8 support

This module provides PKCS#8 private key parsing for supported key types. The SigningKey enum can parse DER-encoded PKCS#8 PrivateKeyInfo structures containing RSA, ECDSA (P-256 and P-384), or Ed25519 keys.

use bssl_crypto::pkcs8;

// A DER-encoded PKCS#8 Ed25519 private key.
let pkcs8_der = [
    0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70,
    0x04, 0x22, 0x04, 0x20, 0x0a, 0x00, 0xc1, 0xfd, 0xfa, 0xaa, 0xdd, 0xc7,
    0x35, 0x79, 0xe0, 0x06, 0x75, 0xc7, 0xcf, 0x57, 0x3a, 0x2c, 0x91, 0xe6,
    0x6a, 0x45, 0x11, 0x0e, 0xbd, 0xde, 0xa9, 0xa7, 0x83, 0xed, 0xbb, 0x86,
];

let key = pkcs8::SigningKey::from_der_private_key_info(&pkcs8_der)
    .expect("valid PKCS#8 key");

match key {
    pkcs8::SigningKey::Ed25519(ed_key) => {
        let signature = ed_key.sign(b"message");
        assert_eq!(signature.len(), 64);
    }
    _ => panic!("expected Ed25519 key"),
}

Enumsยง

SigningKey
PKCS#8 Signing Key