private static string DecryptText(byte[] encrypted, byte[] nonce, byte[] tag, byte[] protectedKey, byte[] entropy) { byte[] key = Protected.Unprotect(protectedKey, entropy, DataProtectionScope.CurrentUser); byte[] decryptedText = aesGCM.Decrypt(encrypted, key, nonce, tag, Encoding.UTF8.GetBytes("some metadata")); return(Encoding.UTF8.GetString(decryptedText)); }
private static void ProtectedDataTest() { var encrypted = Protected.Protect("Mary had a little lamb", "8wef5juy2389f4", DataProtectionScope.CurrentUser); Console.WriteLine(encrypted); var decrypted = Protected.Unprotect(encrypted, "8wef5juy2389f4", DataProtectionScope.CurrentUser); Console.WriteLine(decrypted); }