/// <summary>
        /// This method decrypts a string using the configuration settings supplied
        /// </summary>
        /// <param name="encryptedString">The encrypted string</param>
        /// <returns>The passed in string, decrypted</returns>
        public string DecryptString(string encryptedString)
        {
            string retVal = string.Empty;

            if (!string.IsNullOrEmpty(encryptedString))
            {
                switch (this.EncryptionMethod)
                {
                case EncryptionMethodOptions.None:
                    retVal = encryptedString;
                    break;

                case EncryptionMethodOptions.AES:
                    AESConfiguration aesconfiguration = AESConfiguration.GetInstance();
                    AESManager       aesencryption    = new AESManager(aesconfiguration.EncryptionKey, aesconfiguration.Salt);
                    retVal = aesencryption.Decrypt(encryptedString);
                    break;

                case EncryptionMethodOptions.CertificateKeyFile:
                    KeyFileConfiguration   keyfileConfiguration = KeyFileConfiguration.GetInstance();
                    X509CertificateManager keyfileEncryption    = new X509CertificateManager(keyfileConfiguration.KeyFile, keyfileConfiguration.KeyFilePassword);
                    retVal = keyfileEncryption.Decrypt(encryptedString);
                    break;

                case EncryptionMethodOptions.CertificateKeyStore:
                    KeyStoreConfiguration  keystoreConfiguration = KeyStoreConfiguration.GetInstance();
                    X509CertificateManager keystoreEncryption    = new X509CertificateManager(keystoreConfiguration.StoreName, keystoreConfiguration.StoreLocation, keystoreConfiguration.CertificateName);
                    retVal = keystoreEncryption.Decrypt(encryptedString);
                    break;

                case EncryptionMethodOptions.RSAXmlKeyFile:
                    RSAXmlKeyFileConfiguration rsaxmlKeyFileConfiguration = RSAXmlKeyFileConfiguration.GetInstance();
                    RSAXmlKeyFileManager       rsaxmlKeyFileEncryption    = new RSAXmlKeyFileManager(rsaxmlKeyFileConfiguration.PublicKeyFile, rsaxmlKeyFileConfiguration.PrivateKeyFile);
                    retVal = rsaxmlKeyFileEncryption.Decrypt(encryptedString);
                    break;
                }
            }

            return(retVal);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor with specified configuration
 /// </summary>
 /// <param name="aesConfiguration">The AES configuration instance</param>
 public UserTransferManager(AESConfiguration aesConfiguration) : this(aesConfiguration.EncryptionKey, aesConfiguration.Salt)
 {
 }
Beispiel #3
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public UserTransferManager() : this(AESConfiguration.GetInstance())
 {
 }
        // For Login with AES password hash
        private void BtnLoginAES_Click(object sender, EventArgs e)
        {
            var userName    = UserNameTextbox.Text;
            var password    = PasswordTextBox.Text;
            var encPassword = AESConfiguration.Encrypt(password);



            connectionString = ConfigurationManager.ConnectionStrings["LoginSystemWithRSA"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string query  = "select * from tblUserRegistration where UserName = '******' and Password='******'";
                string cypher = string.Empty;

                SqlCommand cmd = new SqlCommand(query, con);

                try
                {
                    con.Open();

                    var reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        var homePage = new HomePage();
                        homePage.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Failed to login");
                    }

                    reader.Close();



                    //con.Open();
                    //var reader = cmd.ExecuteReader();
                    //if (reader != null)
                    //{
                    //    int count = 0;
                    //    while (reader.Read())
                    //    {
                    //        string tempPass = reader["Password"].ToString();
                    //        cypher = AESConfiguration.Decrypt(tempPass);
                    //        if (cypher == password)
                    //        {
                    //            count++;
                    //            break;
                    //        }

                    //    }
                    //    if (count > 0)
                    //    {
                    //        var homePage = new HomePage();
                    //        homePage.ShowDialog();
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("Invalid username or password!");
                    //    }
                    //}

                    //reader.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Exception occured: " + ex);
                }
                finally
                {
                    con.Close();
                }
            }
        }