public string this[string key, Encoding encoding = null] { get { encoding = encoding ?? Encoding.UTF8; var rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(_files.LoadPrivateKey()); var vault = Vault; if (!vault.HasKey(key)) { return(null); } return(encoding.GetString(rsa.Decrypt(vault[key]))); } }
private void UpdateVault(string publicKey, string privateKey, RSACryptoServiceProvider rsa) { if (_files.VaultExists && _files.PrivateKeyExists) { var vault = _files.Load(); string oldPrivateKey = _files.LoadPrivateKey(); var oldRsa = new RSACryptoServiceProvider(); oldRsa.FromXmlString(oldPrivateKey); CreateVault(publicKey, privateKey, Crypter.ReencryptVault(vault, oldRsa, rsa)); } else { _files.DeletePublicKeyFile(); _files.DeletePrivateKeyFile(); _files.DeleteQuickVault(); CreateVault(publicKey, privateKey); } }