Struct Privkey

Source
pub struct Privkey { /* private fields */ }
Expand description

A private key object

Implementations§

Source§

impl Privkey

Source

pub fn create( alg: &str, params: &str, rng: &mut RandomNumberGenerator, ) -> Result<Privkey>

Create a new private key

Source

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

Source

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

Source

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();
Source

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();
Source

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();
Source

pub fn load_rsa_pkcs1(pkcs1: &[u8]) -> Result<Privkey>

Load a PKCS#1 encoded RSA private key

Source

pub fn load_dh(p: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>

Load an DH private key (p,g,x)

Source

pub fn load_dsa(p: &MPI, q: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>

Load an DSA private key (p,q,g,x)

Source

pub fn load_elgamal(p: &MPI, g: &MPI, x: &MPI) -> Result<Privkey>

Load an ElGamal private key (p,g,x)

Source

pub fn load_ecdsa(s: &MPI, curve_name: &str) -> Result<Privkey>

Load an ECDSA private key with specified curve and secret scalar

Source

pub fn load_ecdh(s: &MPI, curve_name: &str) -> Result<Privkey>

Load an ECDH private key with specified curve and secret scalar

Source

pub fn load_der(der: &[u8]) -> Result<Privkey>

Load DER bytes as an unencrypted PKCS#8 private key

Source

pub fn load_pem(pem: &str) -> Result<Privkey>

Load PEM string as an unencrypted PKCS#8 private key

Source

pub fn load_encrypted_der(der: &[u8], passphrase: &str) -> Result<Privkey>

Load DER bytes as an encrypted PKCS#8 private key

Source

pub fn load_encrypted_pem(pem: &str, passphrase: &str) -> Result<Privkey>

Load PEM string as an encrypted PKCS#8 private key

Source

pub fn check_key(&self, rng: &mut RandomNumberGenerator) -> Result<bool>

Check if the key seems to be valid

Source

pub fn pubkey(&self) -> Result<Pubkey>

Return the public key associated with this private key

Source

pub fn algo_name(&self) -> Result<String>

Return the name of the algorithm

Source

pub fn der_encode(&self) -> Result<Vec<u8>>

DER encode the key (unencrypted)

Source

pub fn pem_encode(&self) -> Result<String>

PEM encode the private key (unencrypted)

Source

pub fn der_encode_encrypted( &self, passphrase: &str, rng: &mut RandomNumberGenerator, ) -> Result<Vec<u8>>

DER encode the key (encrypted)

Source

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

Source

pub fn pem_encode_encrypted( &self, passphrase: &str, rng: &mut RandomNumberGenerator, ) -> Result<String>

PEM encode the key (encrypted)

Source

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

Source

pub fn key_agreement_key(&self) -> Result<Vec<u8>>

Return the key agrement key, only valid for DH/ECDH

Source

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

Source

pub fn get_ed25519_key(&self) -> Result<(Vec<u8>, Vec<u8>)>

Get the public and private key associated with this key

Source

pub fn get_x25519_key(&self) -> Result<Vec<u8>>

Get the X25519 private key

Source

pub fn sign( &self, message: &[u8], padding: &str, rng: &mut RandomNumberGenerator, ) -> Result<Vec<u8>>

Sign a message using the specified padding method

Source

pub fn decrypt(&self, ctext: &[u8], padding: &str) -> Result<Vec<u8>>

Decrypt a message that was encrypted using the specified padding method

Source

pub fn agree( &self, other_key: &[u8], output_len: usize, salt: &[u8], kdf: &str, ) -> Result<Vec<u8>>

Perform key agreement

Trait Implementations§

Source§

impl Debug for Privkey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Privkey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Privkey

Source§

impl Sync for Privkey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.