Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DataProtection sample #1624

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
cargo clippy -p sample_core_app &&
cargo clippy -p sample_create_window &&
cargo clippy -p sample_create_window_sys &&
cargo clippy -p sample_data_protection &&
cargo clippy -p sample_direct2d &&
cargo clippy -p sample_direct3d12 &&
cargo clippy -p sample_enum_windows &&
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
cargo test --target ${{ matrix.target }} -p sample_core_app &&
cargo test --target ${{ matrix.target }} -p sample_create_window &&
cargo test --target ${{ matrix.target }} -p sample_create_window_sys &&
cargo test --target ${{ matrix.target }} -p sample_data_protection &&
cargo test --target ${{ matrix.target }} -p sample_direct2d &&
cargo test --target ${{ matrix.target }} -p sample_direct3d12 &&
cargo test --target ${{ matrix.target }} -p sample_enum_windows &&
Expand Down
13 changes: 13 additions & 0 deletions crates/samples/data_protection/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "sample_data_protection"
version = "0.0.0"
edition = "2018"

[dependencies.windows]
path = "../../libs/windows"
features = [
"alloc",
"Foundation",
"Storage_Streams",
"Security_Cryptography_DataProtection",
]
16 changes: 16 additions & 0 deletions crates/samples/data_protection/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use windows::{core::*, Security::Cryptography::DataProtection::*, Security::Cryptography::*};

fn main() -> Result<()> {
let provider = DataProtectionProvider::CreateOverloadExplicit("LOCAL=user")?;

let buffer = CryptographicBuffer::ConvertStringToBinary("Hello world", BinaryStringEncoding::Utf8)?;

let protected = provider.ProtectAsync(buffer)?.get()?;

let unprotected = provider.UnprotectAsync(protected)?.get()?;

let message = CryptographicBuffer::ConvertBinaryToString(BinaryStringEncoding::Utf8, unprotected)?;

println!("{}", message);
Ok(())
}