Created
October 28, 2015 17:42
-
-
Save adrianstevens/2fe4aa940204c2b4e0ab 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
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
// Perform any additional setup after loading the view, typically from a nib. | |
var password = "9a55W0rd!!"; | |
var salt = Encoding.Unicode.GetBytes("5a1t"); | |
byte[] keymaterial = NetFxCrypto.DeriveBytes.GetBytes(password, salt, 1000, 32); | |
byte[] data = Encoding.UTF8.GetBytes ("Some very important text");//because you should | |
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7); | |
var key = provider.CreateSymmetricKey(keymaterial); | |
byte[] iv = null; // this is optional, but must be the same for both encrypting and decrypting | |
byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(key, data, iv); | |
byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(key, cipherText, iv); | |
var decoded = Encoding.UTF8.GetString(plainText, 0, plainText.Length); | |
Debug.WriteLine (String.Format("decoded: {0}", decoded)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick encryption/decryption example using PCLCrypto (tested on Xamarin.iOS)