Skip to content

Commit 975d30a

Browse files
author
Ron Petrusha
authored
Noted Windows-only support for ProtectedData (dotnet#2465)
* Noted Windows-only support * Addressed review comment
1 parent 8b0ac1b commit 975d30a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

xml/System.Security.Cryptography/ProtectedData.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@
2828
<remarks>
2929
<format type="text/markdown"><![CDATA[
3030
31-
## Remarks
32-
This class provides access to the Data Protection API (DPAPI) available in Microsoft Windows 2000 and later operating systems. This is a service that is provided by the operating system and does not require additional libraries. It provides protection using the user or machine credentials to encrypt or decrypt data.
33-
34-
The class consists of two wrappers for the unmanaged DPAPI, <xref:System.Security.Cryptography.ProtectedData.Protect%2A> and <xref:System.Security.Cryptography.ProtectedData.Unprotect%2A>. These two methods can be used to encrypt and decrypt data such as passwords, keys, and connection strings.
31+
## Remarks
32+
33+
This class provides access to the Data Protection API (DPAPI) available in Windows operating systems. This is a service that is provided by the operating system and does not require additional libraries. It provides protection using the user or machine credentials to encrypt or decrypt data.
34+
35+
> [!IMPORTANT]
36+
> Because it depends on DPAPI, the `ProtectedData` class is supported on the Windows platform only. Its use on .NET Core on platforms other than Windows throws a <xref:System.PlatformNotSupportedException>.
3537
36-
If you use these methods during impersonation, you may receive the following error: "Key not valid for use in specified state." This occurs because the DPAPI stores the key data in user profiles. If the profile is not loaded, DPAPI won't be able to perform the decryption. To prevent this error, load the profile of the user you want to impersonate before calling either method. Using DPAPI with impersonation can incur significant complication and requires careful design choices.
37-
38-
38+
The class consists of two wrappers for the unmanaged DPAPI, <xref:System.Security.Cryptography.ProtectedData.Protect%2A> and <xref:System.Security.Cryptography.ProtectedData.Unprotect%2A>. These two methods can be used to encrypt and decrypt data such as passwords, keys, and connection strings.
3939
40+
If you use these methods during impersonation, you may receive the following error: "Key not valid for use in specified state." This occurs because the DPAPI stores the key data in user profiles. If the profile is not loaded, DPAPI won't be able to perform the decryption. To prevent this error, load the profile of the user you want to impersonate before calling either method. Using DPAPI with impersonation can incur significant complication and requires careful design choices.
41+
4042
## Examples
4143
The following example shows how to use data protection.
4244
@@ -113,6 +115,7 @@
113115
<exception cref="T:System.Security.Cryptography.CryptographicException">The encryption failed.</exception>
114116
<exception cref="T:System.NotSupportedException">The operating system does not support this method.</exception>
115117
<exception cref="T:System.OutOfMemoryException">The system ran out of memory while encrypting the data.</exception>
118+
<exception cref="T:System.PlatformNotSupportedException">.NET Core only: Calls to the <c>Protect</c> method are supported on Windows operating systems only.</exception>
116119
<permission cref="T:System.Security.Permissions.DataProtectionPermission">with the associated <see cref="P:System.Security.Permissions.DataProtectionPermissionAttribute.ProtectData" /> flag for permission to protect data.</permission>
117120
</Docs>
118121
</Member>
@@ -181,6 +184,7 @@
181184
<exception cref="T:System.Security.Cryptography.CryptographicException">The decryption failed.</exception>
182185
<exception cref="T:System.NotSupportedException">The operating system does not support this method.</exception>
183186
<exception cref="T:System.OutOfMemoryException">Out of memory.</exception>
187+
<exception cref="T:System.PlatformNotSupportedException">.NET Core only: Calls to the <c>Unprotect</c> method are supported on Windows operating systems only.</exception>
184188
<permission cref="T:System.Security.Permissions.DataProtectionPermission">with the associated <see cref="P:System.Security.Permissions.DataProtectionPermissionAttribute.UnprotectData" /> flag for permission to unprotect data.</permission>
185189
</Docs>
186190
</Member>

0 commit comments

Comments
 (0)