https://github.com/integrativesoft/crossprotecteddata
A DataProtect wrapper that uses DPAPI in Windows and AspNetCore.DataProtection in other platforms.
https://github.com/integrativesoft/crossprotecteddata
cryptography csharp dpapi encryption protected-data
Last synced: about 1 year ago
JSON representation
A DataProtect wrapper that uses DPAPI in Windows and AspNetCore.DataProtection in other platforms.
- Host: GitHub
- URL: https://github.com/integrativesoft/crossprotecteddata
- Owner: integrativesoft
- License: mit
- Created: 2020-01-10T19:20:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-24T20:27:31.000Z (over 3 years ago)
- Last Synced: 2025-04-11T23:52:54.098Z (about 1 year ago)
- Topics: cryptography, csharp, dpapi, encryption, protected-data
- Language: C#
- Size: 174 KB
- Stars: 18
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CrossProtectedData 
A replacement for the `ProtectedData` class in NET Standard that works not only in Windows but also Linux/MacOS/others.
This library is a wrapper of `ProtectedData` and exposes the same interface. The difference is the following:
- When running in Windows, it calls directly the original ProtectedData class supported in Windows.
- When running in non-Windows, it implements those calls using instead the AspNetCore.DataProtection library.
There is no need to download this repository. This library is available as a [NuGet package](https://www.nuget.org/packages/Integrative.CrossProtect/).
# Example
```csharp
using Integrative.Encryption;
using System;
using System.Security.Cryptography;
using System.Text;
namespace CrossProtectedExample
{
class Program
{
static void Main(string[] args)
{
// our text to protect
var text = "Hello!";
// get bytes from text
var bytes = Encoding.UTF8.GetBytes(text);
// optional entropy
var entropy = new byte[] { 100, 25, 31, 213 };
// protect (encrypt)
var protectedBytes = CrossProtect.Protect(bytes, entropy,
DataProtectionScope.CurrentUser);
// unprotect (decrypt)
var unprotected = CrossProtect.Unprotect(protectedBytes, entropy,
DataProtectionScope.CurrentUser);
// convert bytes back to text
var result = Encoding.UTF8.GetString(unprotected);
// print result
Console.WriteLine(result);
Console.ReadKey();
}
}
}
```