diff --git a/Cargo.toml b/Cargo.toml index 47f9b010..7b633bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ hazmat = [] pkcs1v15 = [] # PKCS #1 v1.5 is only supported as opt-in basis for legacy protocols getrandom = ["crypto-bigint/getrandom", "crypto-common/getrandom"] serde = ["encoding", "dep:serde", "dep:serdect", "crypto-bigint/serde"] -pkcs5 = ["pkcs8/encryption"] +pkcs5 = ["encoding", "pkcs8/encryption"] [lints.clippy] borrow_as_ptr = "warn" diff --git a/src/lib.rs b/src/lib.rs index 5dbe1d5e..067a5580 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,6 +236,17 @@ //! # } //! ``` //! +//! With the `pkcs5` feature, you can also read password-encrypted PKCS#8 keys: +//! +#![cfg_attr(feature = "pkcs5", doc = "```")] +#![cfg_attr(not(feature = "pkcs5"), doc = "```ignore")] +//! use rsa::{PrivateKey, pkcs8::{self, DecodePrivateKey}}; +//! +//! fn load_key(der: &[u8], password: &[u8]) -> pkcs8::Result { +//! PrivateKey::from_pkcs8_encrypted_der(der, password) +//! } +//! ``` +//! //! [RFC8017]: https://www.rfc-editor.org/rfc/rfc8017.html //! // TODO(tarcieri): figure out why rustdoc isn't rendering these links correctly