mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-17 13:31:12 +00:00
feat: generate AGE keys
This commit is contained in:
parent
3abf84e163
commit
2ae22c7ec7
2 changed files with 17 additions and 0 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue