I am playing around with RSA encryption and I have just been using the standard PCKS1 padding which works fine, but I would like to use the more advanced OAEP or PSS Padding schemes. But for some reason when I switch the constant from PCKS1 to PKCS1_OAEP, it compiles but I get a run-time error. Which implies to me that the functionality is there but I am doing something wrong. Here's my code
use openssl::{rsa::{Rsa, Padding}, symm::Cipher};
use bincode;
fn main() {
let rsa = Rsa::generate(512).unwrap();
let password = "password";
let source = "hello paul".to_string();
let data = bincode::serialize(&source).unwrap();
let private = rsa.private_key_to_pem_passphrase(Cipher::aes_128_cbc(), password.as_bytes()).unwrap();
//encrypt
let private_key = Rsa::private_key_from_pem_passphrase(&private, password.as_bytes()).unwrap();
let mut enc_data = vec![0; private_key.size() as usize];
match private_key.private_encrypt(&data, &mut enc_data, Padding::PKCS1_OAEP) {
Ok(_) => {},
Err(e) => {
println!("{e}");
return;
}
}
}
and my Cargo.toml dependencies
[dependencies]
openssl-sys = "0.9.79"
openssl = "0.10.44"
chrono = "0.4"
bincode = "1.0"
serde = { version = "1.0", features = ["derive"] }
and here is the error I am getting.
error:04066076:rsa routines:rsa_ossl_private_encrypt:unknown padding type:crypto/rsa/rsa_ossl.c:273:
So I am getting this from this resource(https://docs.rs/openssl/latest/openssl/rsa/struct.Padding.html#associatedconstant.PKCS1_OAEP) I ahve also tried it with PKCS1_PSS and get the same error. Does anyone know whats up, maybe they never actually finished OAEP or PSS, or is there something wrong on my end? Maybe I need to use a different Cipher than aes_128_cbc? Thanks for reading any help is appreciated.