|
28 | 28 | <remarks>
|
29 | 29 | <format type="text/markdown"><![CDATA[
|
30 | 30 |
|
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>. |
35 | 37 |
|
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. |
39 | 39 |
|
| 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 | +
|
40 | 42 | ## Examples
|
41 | 43 | The following example shows how to use data protection.
|
42 | 44 |
|
|
113 | 115 | <exception cref="T:System.Security.Cryptography.CryptographicException">The encryption failed.</exception>
|
114 | 116 | <exception cref="T:System.NotSupportedException">The operating system does not support this method.</exception>
|
115 | 117 | <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> |
116 | 119 | <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>
|
117 | 120 | </Docs>
|
118 | 121 | </Member>
|
|
181 | 184 | <exception cref="T:System.Security.Cryptography.CryptographicException">The decryption failed.</exception>
|
182 | 185 | <exception cref="T:System.NotSupportedException">The operating system does not support this method.</exception>
|
183 | 186 | <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> |
184 | 188 | <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>
|
185 | 189 | </Docs>
|
186 | 190 | </Member>
|
|
0 commit comments