feat: decrypt print raw data
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use openssl::bn::{BigNum, BigNumContext};
|
||||
use openssl::encrypt::Decrypter;
|
||||
use openssl::pkey::PKey;
|
||||
use openssl::rsa::Rsa;
|
||||
use rust_util::util_clap::{Command, CommandError};
|
||||
use rust_util::util_msg::MessageType;
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
@@ -43,6 +45,16 @@ impl Command for CommandImpl {
|
||||
return simple_error!("Data is required, --data-hex or --data argument!");
|
||||
};
|
||||
|
||||
rust_util::util_msg::when(MessageType::DEBUG, || {
|
||||
let rsa = keypair.rsa().unwrap();
|
||||
let n = rsa.n();
|
||||
let d = rsa.d();
|
||||
let m = BigNum::from_slice(&encrypted).unwrap();
|
||||
let mut r = BigNum::new().unwrap();
|
||||
r.mod_exp(&m, d, n, &mut BigNumContext::new().unwrap()).unwrap();
|
||||
debugging!("Encrypted raw HEX: {}", hex::encode(&r.to_vec()));
|
||||
});
|
||||
|
||||
let mut decrypter = opt_result!(Decrypter::new(&keypair), "Decrypter new failed: {}");
|
||||
opt_result!(decrypter.set_rsa_padding(padding), "Set RSA padding failed: {}");
|
||||
let buffer_len = opt_result!(decrypter.decrypt_len(&encrypted), "Decrypt len failed: {}");
|
||||
|
||||
Reference in New Issue
Block a user