pub struct Privkey { /* private fields */ }Expand description
A private key object
Implementations§
Source§impl Privkey
impl Privkey
Sourcepub fn create(
alg: &str,
params: &str,
rng: &mut RandomNumberGenerator,
) -> Result<Privkey>
pub fn create( alg: &str, params: &str, rng: &mut RandomNumberGenerator, ) -> Result<Privkey>
Create a new private key
Sourcepub fn create_elgamal(
p_bits: usize,
q_bits: usize,
rng: &mut RandomNumberGenerator,
) -> Result<Self>
pub fn create_elgamal( p_bits: usize, q_bits: usize, rng: &mut RandomNumberGenerator, ) -> Result<Self>
Create a new ElGamal private key with a random group
Sourcepub fn create_dsa(
p_bits: usize,
q_bits: usize,
rng: &mut RandomNumberGenerator,
) -> Result<Self>
pub fn create_dsa( p_bits: usize, q_bits: usize, rng: &mut RandomNumberGenerator, ) -> Result<Self>
Create a new DSA private key with a random group
Sourcepub fn load_rsa(p: &MPI, q: &MPI, e: &MPI) -> Result<Privkey>
pub fn load_rsa(p: &MPI, q: &MPI, e: &MPI) -> Result<Privkey>
Load an RSA private key (p,q,e)
§Examples
use std::str::FromStr;
let p = botan::MPI::from_str("289698020102256958291511331409682926199").unwrap();
let q = botan::MPI::from_str("293497288893125842977275290547344412783").unwrap();
let e = botan::MPI::from_str("65537").unwrap();
let rsa = botan::Privkey::load_rsa(&p, &q, &e).unwrap();Sourcepub fn load_ed25519(key: &[u8]) -> Result<Privkey>
pub fn load_ed25519(key: &[u8]) -> Result<Privkey>
Load an Ed25519 private key
§Examples
let v = vec![0x42; 32];
let key = botan::Privkey::load_ed25519(&v).unwrap();Sourcepub fn load_x25519(key: &[u8]) -> Result<Privkey>
pub fn load_x25519(key: &[u8]) -> Result<Privkey>
Load an X25519 private key
§Examples
let v = vec![0x42; 32];
let key = botan::Privkey::load_x25519(&v).unwrap();Sourcepub fn load_rsa_pkcs1(pkcs1: &[u8]) -> Result<Privkey>
pub fn load_rsa_pkcs1(pkcs1: &[u8]) -> Result<Privkey>
Load a PKCS#1 encoded RSA private key
Sourcepub fn load_dsa(p: &MPI, q: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>
pub fn load_dsa(p: &MPI, q: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>
Load an DSA private key (p,q,g,x)
Sourcepub fn load_elgamal(p: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>
pub fn load_elgamal(p: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>
Load an ElGamal private key (p,g,x)
Sourcepub fn load_ecdsa(s: &MPI, curve_name: &str) -> Result<Privkey>
pub fn load_ecdsa(s: &MPI, curve_name: &str) -> Result<Privkey>
Load an ECDSA private key with specified curve and secret scalar
Sourcepub fn load_ecdh(s: &MPI, curve_name: &str) -> Result<Privkey>
pub fn load_ecdh(s: &MPI, curve_name: &str) -> Result<Privkey>
Load an ECDH private key with specified curve and secret scalar
Sourcepub fn load_der(der: &[u8]) -> Result<Privkey>
pub fn load_der(der: &[u8]) -> Result<Privkey>
Load DER bytes as an unencrypted PKCS#8 private key
Sourcepub fn load_pem(pem: &str) -> Result<Privkey>
pub fn load_pem(pem: &str) -> Result<Privkey>
Load PEM string as an unencrypted PKCS#8 private key
Sourcepub fn load_encrypted_der(der: &[u8], passphrase: &str) -> Result<Privkey>
pub fn load_encrypted_der(der: &[u8], passphrase: &str) -> Result<Privkey>
Load DER bytes as an encrypted PKCS#8 private key
Sourcepub fn load_encrypted_pem(pem: &str, passphrase: &str) -> Result<Privkey>
pub fn load_encrypted_pem(pem: &str, passphrase: &str) -> Result<Privkey>
Load PEM string as an encrypted PKCS#8 private key
Sourcepub fn check_key(&self, rng: &mut RandomNumberGenerator) -> Result<bool>
pub fn check_key(&self, rng: &mut RandomNumberGenerator) -> Result<bool>
Check if the key seems to be valid
Sourcepub fn der_encode(&self) -> Result<Vec<u8>>
pub fn der_encode(&self) -> Result<Vec<u8>>
DER encode the key (unencrypted)
Sourcepub fn pem_encode(&self) -> Result<String>
pub fn pem_encode(&self) -> Result<String>
PEM encode the private key (unencrypted)
Sourcepub fn der_encode_encrypted(
&self,
passphrase: &str,
rng: &mut RandomNumberGenerator,
) -> Result<Vec<u8>>
pub fn der_encode_encrypted( &self, passphrase: &str, rng: &mut RandomNumberGenerator, ) -> Result<Vec<u8>>
DER encode the key (encrypted)
Sourcepub fn der_encode_encrypted_with_options(
&self,
passphrase: &str,
cipher: &str,
pbkdf: &str,
pbkdf_iter: usize,
rng: &mut RandomNumberGenerator,
) -> Result<Vec<u8>>
pub fn der_encode_encrypted_with_options( &self, passphrase: &str, cipher: &str, pbkdf: &str, pbkdf_iter: usize, rng: &mut RandomNumberGenerator, ) -> Result<Vec<u8>>
DER encode the key (encrypted), specifying cipher/hash options
Sourcepub fn pem_encode_encrypted(
&self,
passphrase: &str,
rng: &mut RandomNumberGenerator,
) -> Result<String>
pub fn pem_encode_encrypted( &self, passphrase: &str, rng: &mut RandomNumberGenerator, ) -> Result<String>
PEM encode the key (encrypted)
Sourcepub fn pem_encode_encrypted_with_options(
&self,
passphrase: &str,
cipher: &str,
pbkdf: &str,
pbkdf_iter: usize,
rng: &mut RandomNumberGenerator,
) -> Result<String>
pub fn pem_encode_encrypted_with_options( &self, passphrase: &str, cipher: &str, pbkdf: &str, pbkdf_iter: usize, rng: &mut RandomNumberGenerator, ) -> Result<String>
PEM encode the key (encrypted), specifying cipher/hash options
Sourcepub fn key_agreement_key(&self) -> Result<Vec<u8>>
pub fn key_agreement_key(&self) -> Result<Vec<u8>>
Return the key agrement key, only valid for DH/ECDH
Sourcepub fn get_field(&self, which: &str) -> Result<MPI>
pub fn get_field(&self, which: &str) -> Result<MPI>
Get a value for the private key The which parameter selects a field which is algorithm specific
Sourcepub fn get_ed25519_key(&self) -> Result<(Vec<u8>, Vec<u8>)>
pub fn get_ed25519_key(&self) -> Result<(Vec<u8>, Vec<u8>)>
Get the public and private key associated with this key
Sourcepub fn get_x25519_key(&self) -> Result<Vec<u8>>
pub fn get_x25519_key(&self) -> Result<Vec<u8>>
Get the X25519 private key
Sourcepub fn sign(
&self,
message: &[u8],
padding: &str,
rng: &mut RandomNumberGenerator,
) -> Result<Vec<u8>>
pub fn sign( &self, message: &[u8], padding: &str, rng: &mut RandomNumberGenerator, ) -> Result<Vec<u8>>
Sign a message using the specified padding method