[][src]Module openssl::pkey

Public/private key processing.

Asymmetric public key algorithms solve the problem of establishing and sharing secret keys to securely send and receive messages. This system uses a pair of keys: a public key, which can be freely distributed, and a private key, which is kept to oneself. An entity may encrypt information using a user's public key. The encrypted information can only be deciphered using that user's private key.

This module offers support for five popular algorithms:

These algorithms rely on hard mathematical problems - namely integer factorization, discrete logarithms, and elliptic curve relationships - that currently do not yield efficient solutions. This property ensures the security of these cryptographic algorithms.

Example

Generate a 2048-bit RSA public/private key pair and print the public key.


extern crate openssl;

use openssl::rsa::Rsa;
use openssl::pkey::PKey;
use std::str;

fn main() {
    let rsa = Rsa::generate(2048).unwrap();
    let pkey = PKey::from_rsa(rsa).unwrap();

    let pub_key: Vec<u8> = pkey.public_key_to_pem().unwrap();
    println!("{:?}", str::from_utf8(pub_key.as_slice()).unwrap());
}

Structs

Id

An identifier of a kind of key.

PKey

A public or private key.

PKeyRef

Reference to PKey.

Enums

Params

A tag type indicating that a key only has parameters.

Private

A tag type indicating that a key has private components.

Public

A tag type indicating that a key only has public components.

Traits

HasParams

A trait indicating that a key has parameters.

HasPrivate

A trait indicating that a key has private components.

HasPublic

A trait indicating that a key has public components.