public async Task SaveAccessTokens(string clientId, string secretKey) { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(TokenFilename, CreationCollisionOption.ReplaceExisting); var passphrase = (SystemInfo.HardwareIdentifier + clientId + secretKey).ToSecureString(); using (var keyMaterial = KeyMaterial.CreateKeyMaterial(passphrase, 10000)) { var content = Aes.Encrypt(keyMaterial, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(this.tokenInfos))); await file.WriteBytesAsync(content); } }
public void Create_Key_Material_And_Test_Key() { var salt = new byte[] { 14, 11, 202, 234, 78, 19, 148, 146, 17, 71, 187, 141, 123, 7, 124, 192 }; var key = new byte[] { 181, 48, 37, 36, 6, 21, 63, 251, 220, 225, 106, 33, 134, 235, 58, 217, 206, 17, 10, 63, 253, 59, 205, 162, 134, 47, 228, 218, 63, 70, 115, 0 }; var initializationVector = new byte[] { 181, 48, 37, 36, 6, 21, 63, 251, 220, 225, 106, 33, 134, 235, 58, 217 }; using (var keyMaterial = KeyMaterial.CreateKeyMaterial("password1".ToSecureString(), salt, 2000)) { Assert.IsTrue(key.SequenceEqual(keyMaterial.Key)); Assert.IsTrue(initializationVector.SequenceEqual(keyMaterial.InitializationVector)); } }