Example #1
0
        private void SaveHandler(NhanVien item)
        {
            if (String.IsNullOrWhiteSpace(item.Luong) || String.IsNullOrWhiteSpace(item.MatKhau))
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin cho nhân viên " + item.MaNV);
                return;
            }

            var existItem = DbLib.GetOne <NhanVien>("SP_GETBYMANV_PUBLIC_ENCRYPT_NHANVIEN", new List <SqlParameter> {
                new SqlParameter {
                    ParameterName = "MaNV", Value = item.MaNV
                }
            });

            if (existItem != null)
            {
                //ko duoc cap nhat
            }
            //Insert
            else
            {
                item.PubKey = item.MaNV;
                var keyPairs = rsaCryptoService.GenerateKeys();
                KeyRepository.StoreKeyPairs(item.PubKey, keyPairs, item.MatKhau);
                item.MatKhau = item.MatKhau.GetSHA1Hash();

                item.Luong = rsaCryptoService.Encrypt(keyPairs.publicKey, item.Luong);
                DbLib.ExecuteNonQuery("SP_INS_PUBLIC_ENCRYPT_NHANVIEN", item.ToSqlParameter());
            }
        }
Example #2
0
        private void Btn_GenerateKeys_Click(object sender, EventArgs e)
        {
            Rsa = new RSACryptography(Enums.RSAKeySize.Key2048);
            var keys = Rsa.GenerateKeys();

            Txt_PublicKey.Text  = keys.PublicKey;
            Txt_PrivateKey.Text = keys.PrivateKey;
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            RSACryptography rsa    = new RSACryptography();
            var             rsaKey = rsa.GenerateKeys();

            KeyRepository.StorePublicKey(textBox1.Text, rsaKey.publicKey);
            //KeyRepository.StorePrivateKey(textBox1.Text, rsaKey.privateKey);
        }
Example #4
0
        public string GenerateKeys()
        {
            RSACryptography RSA = new RSACryptography();
            string          publicKey, privateKey;

            // Generate RSA key pair
            RSA.GenerateKeys(out publicKey, out privateKey);

            string plainText = "93f99709-ce56-42a9-af7e-1d72c011c2dd";// Guid.NewGuid().ToString();

            // Encrypt
            string encryptedText = RSA.Encrypt(publicKey, plainText);

            // Decrypt
            string decryptedText = RSA.Decrypt(privateKey, encryptedText);

            return(plainText + publicKey + privateKey + encryptedText + decryptedText);
            // return "<b>Token:</b> " + Server.HtmlEncode(plainText) + "<br />" + "<b>Public key:</b> " + Server.HtmlEncode(publicKey) + "<br />" + "<b>Private key:</b> " + Server.HtmlEncode(privateKey) + "<br />" + "<b>Encrypted text:</b> " + Server.HtmlEncode(encryptedText) + "<br />" + "<b>Decrypted text:</b> " + Server.HtmlEncode(decryptedText);
        }