Function decrypt

Source
pub fn decrypt(alg: &str, key: Vec<u8>, ct: Vec<u8>) -> KcapiResult<Vec<u8>>
Expand description

ยงConvenience Function to Perform Asymmetric Decryption

This function decrypts data using a private key. The key must be a Vec<u8> in DER format as follows:

SEQUENCE {
    version INTEGER,
    n INTEGER ({ rsa_get_n }),
    e INTEGER ({ rsa_get_e }),
    d INTEGER ({ rsa_get_d }),
    prime1 INTEGER,
    prime2 INTEGER,
    exponent1 INTEGER,
    exponent2 INTEGER,
    coefficient INTEGER
}

Note: Only self.modsize bytes of data can be decrypted at a time.

This function takes:

  • alg - A &str representation of an akcipher algorithm from /proc/crypto.
  • key - A Vec<u8> with the private key.
  • ct - A Vec<u8> containing the ciphertext to be decrypted.

On success, returns a Vec<u8> wih the decrypted plaintext. On failure, returns KcapiError