pub fn decrypt_data(data: &[u8], scope: Scope) -> Result<Vec<u8>>
Expand description
Decrypts data that was encrypted using Windows DPAPI
§Arguments
data
- The encrypted data to decryptscope
- The encryption scope that was used to encrypt the data
§Returns
Returns a Result
containing the decrypted data as a Vec<u8>
if successful.
§Errors
Returns an error if:
- The Windows API call fails
- The data is corrupted
- The current context does not match the encryption scope (e.g., wrong user or machine)
- The current user doesn’t have permission to decrypt the data
- The data was encrypted on a different machine
§Examples
use windows_dpapi::{encrypt_data, decrypt_data, Scope};
fn main() -> anyhow::Result<()> {
// First encrypt some data
let secret = b"my secret data";
let encrypted = encrypt_data(secret, Scope::User)?;
// Then decrypt it
let decrypted = decrypt_data(&encrypted, Scope::User)?;
assert_eq!(secret, decrypted.as_slice());
Ok(())
}