Expand description
Pure Rust implementation of Public-Key Cryptography Standards (PKCS) #8: Private-Key Information Syntax Specification (RFC 5208), with additional support for PKCS#8v2 asymmetric key packages (RFC 5958)
About PKCS#8
PKCS#8 is a format for cryptographic private keys, often containing pairs of private and public keys.
You can identify a PKCS#8 private key encoded as PEM (i.e. text) by the following:
-----BEGIN PRIVATE KEY-----PKCS#8 private keys can optionally be encrypted under a password using key derivation algorithms like PBKDF2 and scrypt, and encrypted with ciphers like AES-CBC. When a PKCS#8 private key has been encrypted, it starts with the following:
-----BEGIN ENCRYPTED PRIVATE KEY-----PKCS#8 private keys can also be serialized in an ASN.1-based binary format. The PEM text encoding is a Base64 representation of this format.
About this crate
This library provides generalized PKCS#8 support designed to work with a
number of different algorithms. It supports no_std platforms including
ones without a heap (albeit with reduced functionality).
It supports decoding/encoding the following types:
- [
EncryptedPrivateKeyInfo]: (withpkcs5feature) encrypted key. PrivateKeyInfo: algorithm identifier and data representing a private key. Optionally also includes public key data for asymmetric keys.SubjectPublicKeyInfo: algorithm identifier and data representing a public key (re-exported from thespkicrate)
When the alloc feature is enabled, the following additional types are
available which provide more convenient decoding/encoding support:
- [
EncryptedPrivateKeyDocument]: (withpkcs5feature) heap-backed encrypted key. PrivateKeyDocument: heap-backed storage for serializedPrivateKeyInfo.PublicKeyDocument: heap-backed storage for serializedSubjectPublicKeyInfo.
When the pem feature is enabled, it also supports decoding/encoding
documents from “PEM encoding” format as defined in RFC 7468.
Supported Algorithms
This crate has been written generically so it can be used to implement PKCS#8 support for any algorithm.
However, it’s only tested against keys generated by OpenSSL for the following algorithms:
- ECC (
id-ecPublicKey) - Ed25519 (
Ed25519) - RSA (
rsaEncryption)
Please open an issue if you encounter trouble using it with other algorithms.
Encrypted Private Key Support
[EncryptedPrivateKeyInfo] supports decoding/encoding encrypted PKCS#8
private keys and is gated under the pkcs5 feature. The corresponding
[EncryptedPrivateKeyDocument] type provides heap-backed storage
(alloc feature required).
When the encryption feature of this crate is enabled, it provides
[EncryptedPrivateKeyInfo::decrypt] and [PrivateKeyInfo::encrypt]
functions which are able to decrypt/encrypt keys using the following
algorithms:
- PKCS#5v2 Password Based Encryption Scheme 2 (RFC 8018)
- Key derivation functions:
- Symmetric encryption: AES-128-CBC, AES-192-CBC, or AES-256-CBC (best available options for PKCS#5v2)
Legacy DES-CBC and DES-EDE3-CBC (3DES) support (optional)
When the des-insecure and/or 3des features are enabled this crate provides support for
private keys encrypted with with DES-CBC and DES-EDE3-CBC (3DES or Triple DES) symmetric
encryption, respectively.
⚠️ WARNING ⚠️
DES support is implemented to allow for decryption of legacy files.
DES is considered insecure due to its short key size. New keys should use AES instead.
PKCS#1 support (optional)
When the pkcs1 feature of this crate is enabled, this crate provides
a blanket impl of PKCS#8 support for types which impl the traits from the
[pkcs1] crate (e.g. FromRsaPrivateKey, ToRsaPrivateKey).
Minimum Supported Rust Version
This crate requires Rust 1.51 at a minimum.
Re-exports
pub use der;Structs
X.509 AlgorithmIdentifier as defined in RFC 5280 Section 4.1.1.2.
Attributes as defined in RFC 5958 Section 2.
Object identifier (OID).
PKCS#8 private key document.
PKCS#8 PrivateKeyInfo.
SPKI public key document.
X.509 SubjectPublicKeyInfo (SPKI) as defined in RFC 5280 Section 4.1.2.7.
Enums
Traits
Parse a private key object from a PKCS#8 encoded document.
Parse a public key object from an encoded SPKI document.
Serialize a private key object to a PKCS#8 encoded document.
Serialize a public key object to a SPKI-encoded document.
Type Definitions
Result type