Function encrypt_data

Source
pub fn encrypt_data(data: &[u8], scope: Scope) -> Result<Vec<u8>>
Expand description

Encrypts data using Windows DPAPI

§Arguments

  • data - The data to encrypt
  • scope - The encryption scope (User or Machine)

§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 encrypted = encrypt_data(secret, Scope::User)?;
    Ok(())
}