private void handleDecryptBangDiem(BangDiem item)
 {
     if (!String.IsNullOrEmpty(privateKey))
     {
         item.DiemThi = rsaCryptoService.Decrypt(privateKey, item.DiemThi.ToString());
     }
 }
Exemple #2
0
        private void handleDecryptLuong(NhanVien item)
        {
            var priKey = KeyRepository.GetPrivateKey(this.nhanVienDangNhap.PubKey, password);

            if (!String.IsNullOrEmpty(priKey))
            {
                item.Luong = rsaCryptoService.Decrypt(priKey, item.Luong);
            }
        }
Exemple #3
0
        public string GenerateKeys(string key1, string key2, string dtcreate)
        {
            RSACryptography RSA = new RSACryptography();
            string          publicKey, privateKey, dtcreates;

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

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

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

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

            File.WriteAllText(Application.StartupPath + "\\PrivateKey.xml", privateKey);
            File.WriteAllText(Application.StartupPath + "\\PublicKey.xml", publicKey);
            File.WriteAllText(Application.StartupPath + "\\DateKey.xml", dtcreates);
            MessageBox.Show("The Key pair created successfully at:\n" + Application.StartupPath);
            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);
        }
Exemple #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);
        }
Exemple #5
0
        public static void TestCommutative()
        {
            var rsa        = new RSACryptography();
            var privateKey = rsa.KeyCreator.CreatePrivateKey();
            var publicKey  = rsa.KeyCreator.CreatePublicKey(privateKey);
            var blindKey   = rsa.KeyCreator.CreateBlindKey();
            var msg        = Encoding.UTF7.GetBytes("sdlfjsf;slkfslkfddfshkfksjfhsjhfsjldfslkjfslakddsfklsjdflsdkfjsjgakdglkjjkdfhgdkjfghlskdhgklshdglsjdfhgjshfjsdhfkshfsdgfjshgfasldhalskdjalskfsdhjkfsdhfgsfkjaghsjlkfhasdohdfgskljafskhfgkflsdjfkljnzjzzmnznzzzzzzzzzzzzzz");

            Console.WriteLine(Encoding.UTF7.GetString(msg));
            var encrypted = rsa.Encrypt(publicKey, msg);
            var decrypted = rsa.Decrypt(privateKey, encrypted);

            Console.WriteLine(Encoding.UTF7.GetString(decrypted));

            var B          = Encoding.UTF8.GetBytes("B");
            var blindB     = rsa.BlindData(blindKey, publicKey, B);
            var signB      = rsa.SignData(privateKey, B);
            var signBlindB = rsa.SignData(privateKey, blindB);
            var blindSignB = rsa.BlindData(blindKey, publicKey, signB);

            Console.WriteLine($"Commutative = {signBlindB.SequenceEqual(blindSignB)}");
            Console.WriteLine($"Verify test = {rsa.VerifyData(publicKey, B, signB)}");
        }