From 2ae22c7ec70910a469e4c11bd758ea47499b77f1 Mon Sep 17 00:00:00 2001 From: EETagent Date: Fri, 28 Oct 2022 15:24:07 +0200 Subject: [PATCH] feat: generate AGE keys --- core/Cargo.toml | 1 + core/src/crypto.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/core/Cargo.toml b/core/Cargo.toml index 67be561..7635b5b 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,6 +16,7 @@ futures = "0.3.25" # crypto argon2 = { version = "0.4", features = ["std"] } age = { version = "0.9", features = ["async"] } +secrecy = { version = "0.8.0" } base64 = "0.13" [dependencies.sea-orm] diff --git a/core/src/crypto.rs b/core/src/crypto.rs index 3484592..bacc3fe 100644 --- a/core/src/crypto.rs +++ b/core/src/crypto.rs @@ -1,6 +1,7 @@ use argon2::{ Argon2, PasswordHasher as ArgonPasswordHasher, PasswordVerifier as ArgonPasswordVerifier, }; +use secrecy::ExposeSecret; use futures::io::{AsyncReadExt, AsyncWriteExt}; use rand::Rng; use std::iter; @@ -109,6 +110,13 @@ pub async fn decrypt_password( Ok(String::from_utf8(decrypt_buffer)?) } +pub fn create_identity() -> (String, String){ + let identity = age::x25519::Identity::generate(); + + // Public Key & Private Key + (identity.to_public().to_string(), identity.to_string().expose_secret().to_string()) +} + pub async fn encrypt_password_with_recipients( password_plain_text: &str, recipients: Vec<&str>, @@ -271,6 +279,14 @@ mod tests { assert_eq!(PASSWORD, decrypted); } + + #[test] + fn test_create_identity() { + let identity = super::create_identity(); + + assert!(identity.0.contains("age")); + assert!(identity.1.contains("AGE-SECRET-KEY-")); + } #[tokio::test] async fn test_encrypt_password_with_recipients_is_valid_base64() {