void Persons_SelectedItemChanged(object selectedItem) { StringItemViewModel item = selectedItem as StringItemViewModel; if (item == null) { return; } Jobs.Items.Clear(); Jobs.Items.Add(new StringItemViewModel((item.Text.Contains("Ivan") ? "Programmer":"Warrior"))); }
public void EncryptString(StringItemViewModel stringToEncrypt) { if (stringToEncrypt.IsEncrypted) { IBuffer stringBuffer = CryptographicBuffer.ConvertStringToBinary(stringToEncrypt.Content, BinaryStringEncoding.Utf8); var encryptedString = CryptographicEngine.EncryptAndAuthenticate(aesKey, stringBuffer, stringToEncrypt.Nonce, null); stringToEncrypt.AuthenticationTag = encryptedString.AuthenticationTag; stringToEncrypt.Content = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, encryptedString.EncryptedData); stringToEncrypt.IsEncrypted = true; } else { throw new Exception("Tried to encrypt string with encrypted flag set to true"); } }
public void DecryptString(StringItemViewModel stringToDecrypt) { if (stringToDecrypt.IsEncrypted) { var stringBuffer = CryptographicBuffer.ConvertStringToBinary(stringToDecrypt.Content, BinaryStringEncoding.Utf8); var decryptedString = CryptographicEngine.DecryptAndAuthenticate(aesKey, stringBuffer, stringToDecrypt.Nonce, stringToDecrypt.AuthenticationTag, null); stringToDecrypt.Content = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, decryptedString); stringToDecrypt.IsEncrypted = false; } else { throw new Exception("Tried to encrypt string with encrypted flag set to false"); } }