Skip to content

Clarify .NET package and platform requirements for the data protection sample - #54853

Merged
adegeo merged 8 commits into
mainfrom
copilot/fix-data-protection-code-sample
Jul 22, 2026
Merged

Clarify .NET package and platform requirements for the data protection sample#54853
adegeo merged 8 commits into
mainfrom
copilot/fix-data-protection-code-sample

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

The data protection article's sample guidance was incomplete for modern .NET. Readers could resolve ProtectedData by adding the package, but the article didn't explain that requirement or that the ProtectedMemory portion remains .NET Framework-only.

  • What changed

    • Added an upfront note that .NET on Windows requires the System.Security.Cryptography.ProtectedData NuGet package before you use ProtectedData or DataProtectionScope.
    • Expanded the compile guidance to distinguish modern .NET from .NET Framework.
    • Explicitly called out that ProtectedMemory and MemoryProtectionScope aren't supported on .NET, so the full sample doesn't compile there.
  • Updated guidance

    • .NET Framework: use the article sample as written.
    • .NET: install System.Security.Cryptography.ProtectedData for the ProtectedData APIs, but don't expect the ProtectedMemory portion to compile.
  • Example

    using System.Security.Cryptography;
    
    byte[] input = [1, 2, 3, 4];
    byte[] entropy = [5, 6, 7, 8];
    
    byte[] cipher = ProtectedData.Protect(input, entropy, DataProtectionScope.CurrentUser);
    byte[] plain = ProtectedData.Unprotect(cipher, entropy, DataProtectionScope.CurrentUser);

Internal previews

📄 File 🔗 Preview link
docs/standard/security/how-to-use-data-protection.md How to use data protection

Copilot AI review requested due to automatic review settings July 21, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI changed the title [WIP] Fix compilation errors in Data Protection code sample Clarify .NET package and platform requirements for the data protection sample Jul 21, 2026
Copilot AI requested a review from adegeo July 21, 2026 23:28
@adegeo

adegeo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@copilot ad a note in the example section that mentions the ProtectedMemory API isn't available on .NET (it's only available on .NET Framework) and that the methods EncryptInMemoryData and DecryptInMemoryData won't compile.

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ad a note in the example section that mentions the ProtectedMemory API isn't available on .NET (it's only available on .NET Framework) and that the methods EncryptInMemoryData and `Decryp...

Addressed in 57c0e05.

@adegeo
adegeo marked this pull request as ready for review July 22, 2026 20:46
@adegeo
adegeo requested review from a team and BillWagner as code owners July 22, 2026 20:46

@BillWagner BillWagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Let's :shipit:

@adegeo
adegeo merged commit 29d3038 into main Jul 22, 2026
12 checks passed
@adegeo
adegeo deleted the copilot/fix-data-protection-code-sample branch July 22, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"How to: Use Data Protection" code sample does not compile

4 participants