✖️ replace pgp crate
This commit is contained in:
parent
31c20fff10
commit
4ddadfdce9
6 changed files with 30 additions and 704 deletions
16
src/msg.rs
16
src/msg.rs
|
@ -1,19 +1,11 @@
|
|||
use pgp::crypto::SymmetricKeyAlgorithm;
|
||||
use pgp::{Deserializable, Message, SignedPublicKey};
|
||||
use std::io::Write;
|
||||
|
||||
pub fn encrypt(msg: String) -> String {
|
||||
// err: Encryption is done twice
|
||||
let pub_key =
|
||||
SignedPublicKey::from_string(&*std::fs::read_to_string("/config/pub.key").unwrap())
|
||||
.unwrap()
|
||||
.0;
|
||||
let mut rng = rand::thread_rng();
|
||||
let c = Message::new_literal("msg", &msg)
|
||||
.encrypt_to_keys(&mut rng, SymmetricKeyAlgorithm::AES128, &[&pub_key])
|
||||
.unwrap()
|
||||
.to_armored_string(None)
|
||||
let pgp = gnupg::GnuPG::new().unwrap();
|
||||
let pub_key = pgp
|
||||
.import_key(&std::fs::read_to_string("/config/pub.key").unwrap())
|
||||
.unwrap();
|
||||
let c = pgp.encrypt(&pub_key, &msg).unwrap();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ pub struct MessageForm {
|
|||
#[post("/message")]
|
||||
pub async fn message_post(r: HttpRequest, f: Form<MessageForm>) -> impl Responder {
|
||||
let config: &web::Data<config::Config> = r.app_data().unwrap();
|
||||
let cipher = crate::msg::encrypt(f.message.to_string());
|
||||
crate::msg::save_msg(cipher, &f.msg_name.to_string());
|
||||
crate::msg::save_msg(f.message.clone(), &f.msg_name.to_string());
|
||||
crate::notification::notify(
|
||||
&format!("New Message from {}", f.msg_name.to_string()),
|
||||
"New Message",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue