Last active
October 17, 2017 18:02
-
-
Save mkropat/49d8be90eb2eec96975b6201038e7b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Statements"> | |
<Reference><RuntimeDirectory>\System.Security.dll</Reference> | |
<Namespace>System.Security.Cryptography</Namespace> | |
</Query> | |
var scope = DataProtectionScope.CurrentUser; | |
var data = Encoding.UTF8.GetBytes("hello, world (privately)"); | |
var encrypted = ProtectedData.Protect(data, null, scope); | |
BitConverter.ToString(encrypted).Dump("encrypted"); | |
var decrypted = ProtectedData.Unprotect(encrypted, null, scope); | |
Encoding.UTF8.GetString(decrypted).Dump("decrypted"); | |
var tampered = encrypted.ToArray(); | |
tampered[encrypted.Length - 1] = 0xff; | |
ProtectedData.Unprotect(tampered, null, scope); // throws CryptographicException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment