Exemplo n.º 1
0
        public async Task SetCredentials(string userName, string password)
        {
            UserName = userName;
            //// Returns client key & public key
            EncryptPasswordResponse results = await authApi.RegisterAndGetPublicKey();

            //// Encrypt the password
            RsaEncryptionService encryptionService = new RsaEncryptionService {
                PublicKey = results.PublicKey
            };

            EncryptedPassword = encryptionService.EncryptString(password);

            ClientKey = results.ClientKey;
            PublicKey = results.PublicKey;

            //// Store client key, encrypted pw & public key
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            configuration.AppSettings.Settings["ClientKey"].Value         = results.ClientKey;
            configuration.AppSettings.Settings["PublicKey"].Value         = results.PublicKey;
            configuration.AppSettings.Settings["EncryptedPassword"].Value = EncryptedPassword;
            configuration.Save(ConfigurationSaveMode.Full);
            ConfigurationManager.RefreshSection("appSettings");
        }