pub fn from_seed(seed: &WalletSeed, password: &str) -> Result<EncryptedWalletSeed, Error> {
		let salt: [u8; 8] = thread_rng().gen();
		let nonce: [u8; 12] = thread_rng().gen();
		let password = password.as_bytes();
		let mut key = [0; 32];
		pbkdf2::derive(&digest::SHA512, 100, &salt, password, &mut key);
		let content = seed.0.to_vec();
		let mut enc_bytes = content.clone();
		let suffix_len = aead::CHACHA20_POLY1305.tag_len();
		for _ in 0..suffix_len {
			enc_bytes.push(0);
		}
		let sealing_key =
			aead::SealingKey::new(&aead::CHACHA20_POLY1305, &key).context(ErrorKind::Encryption)?;
		aead::seal_in_place(&sealing_key, &nonce, &[], &mut enc_bytes, suffix_len)
			.context(ErrorKind::Encryption)?;
		Ok(EncryptedWalletSeed {
			encrypted_seed: util::to_hex(enc_bytes.to_vec()),
			salt: util::to_hex(salt.to_vec()),
			nonce: util::to_hex(nonce.to_vec()),
		})
	}
/// Create a new encrypted seed from the given seed + password
Create a new encrypted seed from the given seed + password
Create a new encrypted seed from the given seed + password
pub fn from_seed(seed: &WalletSeed, password: &str) -> Result<EncryptedWalletSeed, Error> {
		let salt: [u8; 8] = thread_rng().gen();
		let nonce: [u8; 12] = thread_rng().gen();
		let password = password.as_bytes();
		let mut key = [0; 32];
		pbkdf2::derive(&digest::SHA512, 100, &salt, password, &mut key);
		let content = seed.0.to_vec();
		let mut enc_bytes = content.clone();
		let suffix_len = aead::CHACHA20_POLY1305.tag_len();
		for _ in 0..suffix_len {
			enc_bytes.push(0);
		}
		let sealing_key =
			aead::SealingKey::new(&aead::CHACHA20_POLY1305, &key).context(ErrorKind::Encryption)?;
		aead::seal_in_place(&sealing_key, &nonce, &[], &mut enc_bytes, suffix_len)
			.context(ErrorKind::Encryption)?;
		Ok(EncryptedWalletSeed {
			encrypted_seed: util::to_hex(enc_bytes.to_vec()),
			salt: util::to_hex(salt.to_vec()),
			nonce: util::to_hex(nonce.to_vec()),
		})
	}
pub fn from_seed ( seed : & WalletSeed , password : & str ) -> Result < EncryptedWalletSeed , Error > { let salt : [ u8 ; 8 ] = thread_rng ( ) . gen ( ) ; let nonce : [ u8 ; 12 ] = thread_rng ( ) . gen ( ) ; let password = password . as_bytes ( ) ; let mut key = [ 0 ; 32 ] ; pbkdf2 :: derive ( & digest :: SHA512 , 100 , & salt , password , & mut key ) ; let content = seed . 0 . to_vec ( ) ; let mut enc_bytes = content . clone ( ) ; let suffix_len = aead :: CHACHA20_POLY1305 . tag_len ( ) ; for _ in 0 .. suffix_len { enc_bytes . push ( 0 ) ; } let sealing_key = aead :: SealingKey :: new ( & aead :: CHACHA20_POLY1305 , & key ) . context ( ErrorKind :: Encryption ) ? ; aead :: seal_in_place ( & sealing_key , & nonce , & [ ] , & mut enc_bytes , suffix_len ) . context ( ErrorKind :: Encryption ) ? ; Ok ( EncryptedWalletSeed { encrypted_seed : util :: to_hex ( enc_bytes . to_vec ( ) ) , salt : util :: to_hex ( salt . to_vec ( ) ) , nonce : util :: to_hex ( nonce . to_vec ( ) ) , } ) }
Create a new encrypted seed from the given seed + password
Create a new encrypted seed from the given seed + password
seed
&WalletSeed
password
&str