pub struct Oaep<D, MGD = D> {
pub digest: D,
pub mgf_digest: MGD,
pub label: Option<Box<[u8]>>,
}Expand description
Encryption and Decryption using OAEP padding.
digestis used to hash the label. The maximum possible plaintext length ism = k - 2 * h_len - 2, wherekis the size of the RSA modulus.mgf_digestspecifies the hash function that is used in the MGF1.labelis optional data that can be associated with the message.
The two hash functions can, but don’t need to be the same.
A prominent example is the AndroidKeyStore.
It uses SHA-1 for mgf_digest and a user-chosen SHA flavour for digest.
Fields§
§digest: DDigest type to use.
mgf_digest: MGDDigest to use for Mask Generation Function (MGF).
label: Option<Box<[u8]>>Optional label.
Implementations§
Source§impl<D> Oaep<D>where
D: Digest + FixedOutputReset,
impl<D> Oaep<D>where
D: Digest + FixedOutputReset,
Sourcepub fn new() -> Oaep<D>
pub fn new() -> Oaep<D>
Create a new OAEP PaddingScheme, using T as the hash function for both the default (empty) label and for MGF1.
§Example
use sha1::Sha1;
use sha2::Sha256;
use rsa::{RsaPublicKey, Oaep};
use base64ct::{Base64, Encoding};
use crypto_bigint::BoxedUint;
let n_bytes = Base64::decode_vec("seAOhmYFAjH6NOaB54dboqw86uPXV/oK9ayJGV4mVClbvsDBJmF3bVkOaVMp9ogcFJTFFSy5g2HsTZIfHyuQVUJADb+BeRnkYrYhRvNJOKj2pcDbkxYe9XGMx8pIvxkDFnIpusb3gUsuzMUAU5qIstjwQKzuD51c6uJi0HAtQkr6Wmlt34SX7xkD/MfRuTu9uqmHmkiiJaCDHB2reYTPguetSWfuvp1qBJDNgSsp7BjwYANWldyrmZ8cLXEXYMUG5vtsWMxUzl8ertEr6kbnGM0OJghNuEtittW/dfTPvk683R1jj0hNaMzvHK8xYldUlLuwmWCYIIvpHBaA/w+FwQ==").unwrap();
let e_bytes = Base64::decode_vec("AQAB").unwrap();
let n = BoxedUint::from_be_slice(&n_bytes, 2048).unwrap();
let e = BoxedUint::from_be_slice(&e_bytes, 32).unwrap();
let mut rng = rand::rng();
let key = RsaPublicKey::new(n, e).unwrap();
let padding = Oaep::<Sha256>::new();
let encrypted_data = key.encrypt(&mut rng, padding, b"secret").unwrap();Source§impl<D, MGD> Oaep<D, MGD>
impl<D, MGD> Oaep<D, MGD>
Sourcepub fn new_with_mgf_hash() -> Oaep<D, MGD>
pub fn new_with_mgf_hash() -> Oaep<D, MGD>
Create a new OAEP PaddingScheme, using T as the hash function for the default (empty) label, and U as the hash function for MGF1.
If a label is needed use PaddingScheme::new_oaep_with_label or PaddingScheme::new_oaep_with_mgf_hash_with_label.
§Example
use sha1::Sha1;
use sha2::Sha256;
use rsa::{RsaPublicKey, Oaep};
use base64ct::{Base64, Encoding};
use crypto_bigint::BoxedUint;
let n_bytes = Base64::decode_vec("seAOhmYFAjH6NOaB54dboqw86uPXV/oK9ayJGV4mVClbvsDBJmF3bVkOaVMp9ogcFJTFFSy5g2HsTZIfHyuQVUJADb+BeRnkYrYhRvNJOKj2pcDbkxYe9XGMx8pIvxkDFnIpusb3gUsuzMUAU5qIstjwQKzuD51c6uJi0HAtQkr6Wmlt34SX7xkD/MfRuTu9uqmHmkiiJaCDHB2reYTPguetSWfuvp1qBJDNgSsp7BjwYANWldyrmZ8cLXEXYMUG5vtsWMxUzl8ertEr6kbnGM0OJghNuEtittW/dfTPvk683R1jj0hNaMzvHK8xYldUlLuwmWCYIIvpHBaA/w+FwQ==").unwrap();
let e_bytes = Base64::decode_vec("AQAB").unwrap();
let n = BoxedUint::from_be_slice(&n_bytes, 2048).unwrap();
let e = BoxedUint::from_be_slice(&e_bytes, 32).unwrap();
let mut rng = rand::rng();
let key = RsaPublicKey::new(n, e).unwrap();
let padding = Oaep::<Sha256, Sha1>::new_with_mgf_hash();
let encrypted_data = key.encrypt(&mut rng, padding, b"secret").unwrap();Trait Implementations§
Auto Trait Implementations§
impl<D, MGD> Freeze for Oaep<D, MGD>
impl<D, MGD> RefUnwindSafe for Oaep<D, MGD>where
D: RefUnwindSafe,
MGD: RefUnwindSafe,
impl<D, MGD> Send for Oaep<D, MGD>
impl<D, MGD> Sync for Oaep<D, MGD>
impl<D, MGD> Unpin for Oaep<D, MGD>
impl<D, MGD> UnsafeUnpin for Oaep<D, MGD>where
D: UnsafeUnpin,
MGD: UnsafeUnpin,
impl<D, MGD> UnwindSafe for Oaep<D, MGD>where
D: UnwindSafe,
MGD: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more