pub fn encrypt_hashed(data: &[u8], key: &Key, random_bytes: &[u8; 256]) -> Vec<u8> {
    // Sha1::digest's len is always 20, we're left with 255 - 20 - x padding.
    let to_encrypt = {
        // sha1
        let mut buffer = Vec::with_capacity(255);
        buffer.extend(&Sha1::from(data).digest().bytes());

        // + data
        buffer.extend(data);

        // + padding
        let padding_len = 255 - 20 - data.len();
        let mut padding = vec![0; padding_len];
        padding.copy_from_slice(&random_bytes[..padding_len]);
        buffer.extend(&padding);

        buffer
    };

    let payload = BigUint::from_bytes_be(&to_encrypt);
    let encrypted = payload.modpow(&key.e, &key.n);
    let mut block = encrypted.to_bytes_be();
    while block.len() < 256 {
        block.insert(0, 0);
    }

    block
}
/// Encrypt the given data, prefixing it with a hash before, using RSA.
Encrypt the given data, prefixing it with a hash before, using RSA.
Encrypt the given data prefixing it with a hash before using RSA .
pub fn encrypt_hashed(data: &[u8], key: &Key, random_bytes: &[u8; 256]) -> Vec<u8> {
    // Sha1::digest's len is always 20, we're left with 255 - 20 - x padding.
    let to_encrypt = {
        // sha1
        let mut buffer = Vec::with_capacity(255);
        buffer.extend(&Sha1::from(data).digest().bytes());
        // + data
        buffer.extend(data);
        // + padding
        let padding_len = 255 - 20 - data.len();
        let mut padding = vec![0; padding_len];
        padding.copy_from_slice(&random_bytes[..padding_len]);
        buffer.extend(&padding);
        buffer
    };
    let payload = BigUint::from_bytes_be(&to_encrypt);
    let encrypted = payload.modpow(&key.e, &key.n);
    let mut block = encrypted.to_bytes_be();
    while block.len() < 256 {
        block.insert(0, 0);
    }
    block
}
pub fn encrypt_hashed ( data : & [ u8 ] , key : & Key , random_bytes : & [ u8 ; 256 ] ) -> Vec < u8 > { // Sha1::digest's len is always 20, we're left with 255 - 20 - x padding. let to_encrypt = { // sha1 let mut buffer = Vec :: with_capacity ( 255 ) ; buffer . extend ( & Sha1 :: from ( data ) . digest ( ) . bytes ( ) ) ; // + data buffer . extend ( data ) ; // + padding let padding_len = 255 - 20 - data . len ( ) ; let mut padding = vec ! [ 0 padding_len ] ; padding . copy_from_slice ( & random_bytes [ .. padding_len ] ) ; buffer . extend ( & padding ) ; buffer } ; let payload = BigUint :: from_bytes_be ( & to_encrypt ) ; let encrypted = payload . modpow ( & key . e , & key . n ) ; let mut block = encrypted . to_bytes_be ( ) ; while block . len ( ) < 256 { block . insert ( 0 , 0 ) ; } block }
Encrypt the given data, prefixing it with a hash before, using RSA.
Encrypt the given data prefixing it with a hash before using RSA .
data
&[u8]
key
&Key
random_bytes
&[u8; 256]
data
&[u8]
key
&Key
random_bytes
&[u8; 256]