Add crypto generate_key function
This commit is contained in:
parent
f20a95ad56
commit
525d7f14a8
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Error, Result};
|
use anyhow::Result;
|
||||||
use sp_client::silentpayments::{
|
use sp_client::silentpayments::{
|
||||||
bitcoin_hashes::{sha256t_hash_newtype, Hash, HashEngine},
|
bitcoin_hashes::{sha256t_hash_newtype, Hash, HashEngine},
|
||||||
secp256k1::PublicKey,
|
secp256k1::PublicKey,
|
||||||
@ -6,7 +6,7 @@ use sp_client::silentpayments::{
|
|||||||
|
|
||||||
use aes_gcm::aead::{Aead, Payload};
|
use aes_gcm::aead::{Aead, Payload};
|
||||||
pub use aes_gcm::{AeadCore, Aes256Gcm, KeyInit};
|
pub use aes_gcm::{AeadCore, Aes256Gcm, KeyInit};
|
||||||
use rand::thread_rng;
|
use rand::{thread_rng, CryptoRng, RngCore};
|
||||||
|
|
||||||
pub const AAD: &[u8] = "4nk".as_bytes();
|
pub const AAD: &[u8] = "4nk".as_bytes();
|
||||||
|
|
||||||
@ -25,6 +25,11 @@ impl AnkSharedSecretHash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn generate_key(rng: &mut (impl CryptoRng + RngCore)) -> [u8; 32] {
|
||||||
|
let key = Aes256Gcm::generate_key(rng);
|
||||||
|
key.into()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn encrypt_with_key(key: &[u8; 32], plaintext: &[u8]) -> Result<Vec<u8>> {
|
pub fn encrypt_with_key(key: &[u8; 32], plaintext: &[u8]) -> Result<Vec<u8>> {
|
||||||
let encryption_eng = Aes256Gcm::new(key.into());
|
let encryption_eng = Aes256Gcm::new(key.into());
|
||||||
let nonce = Aes256Gcm::generate_nonce(&mut thread_rng());
|
let nonce = Aes256Gcm::generate_nonce(&mut thread_rng());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user