Ejemplo n.º 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;
        }
Ejemplo n.º 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!");
            }
        }