pub(crate) fn encrypt_key(private_key: Vec<u8>, pwd: Vec<u8>) -> Result<Vec<u8>>Expand description
Encrypts a private key using AES-256-GCM with PBKDF2 key derivation
§Arguments
private_key- The private key bytes to encryptpwd- The password bytes to derive the encryption key from
§Returns
Result<Vec<u8>>- The encrypted data containing salt, nonce, and ciphertext
§Format
The returned encrypted data has the following structure:
- Bytes 0-31: Salt (32 bytes)
- Bytes 32-43: Nonce (12 bytes)
- Bytes 44+: Ciphertext with authentication tag
§Security
- Uses AES-256-GCM for authenticated encryption
- Derives key using PBKDF2-HMAC-SHA256 with 100,000 iterations
- Generates random salt and nonce for each encryption