Example #1
0
        public void LoadKeys(string masterPassword)
        {
            string pathToKeyFile = GetPrivateKeyPath(UserId);

            var rsaKeysXml = FileCryptor.LoadAndDecryptRsaKeys(pathToKeyFile, masterPassword);

            rsa = new RSACryptoServiceProvider();
            rsa.FromXmlString(rsaKeysXml);
            rsa.PersistKeyInCsp = true;
        }
Example #2
0
        public void SaveKeys(string masterPassword, bool force = false)
        {
            string pathToKeyFile = GetPrivateKeyPath(UserId);

            if (!File.Exists(pathToKeyFile) || force)
            {
                var rsaKeysXml = rsa.ToXmlString(true);

                FileCryptor.EncryptAndSaveRsaKeys(rsaKeysXml, pathToKeyFile, masterPassword);
            }
            else
            {
                throw new ArgumentException("Keys for this user already exist!");
            }
        }