pub fn encrypt_data(
data: &[u8],
scope: Scope,
entropy: Option<&[u8]>,
) -> Result<Vec<u8>>Expand description
Encrypts data using Windows DPAPI
§Arguments
data- The data to encryptscope- The encryption scope (User or Machine)entropy- Optional additional entropy data to strengthen encryption
§Returns
Returns a Result containing the encrypted data as a Vec<u8> if successful.
§Errors
Returns an error if:
- The Windows API call fails
- Memory allocation fails
- The current user doesn’t have permission to encrypt data
§Examples
use windows_dpapi::{encrypt_data, Scope};
fn main() -> anyhow::Result<()> {
let secret = b"my secret data";
let entropy = b"my entropy";
let encrypted = encrypt_data(secret, Scope::User, Some(entropy))?;
Ok(())
}