Exemple #1
0
        public static void HybridIntergityCheckEncrypDecrypt()
        {
            const string original = "Very secret and important information that can not into the hacker.";

            var hybrid = new HybridEncryptionIntegirtyCheck();

            var rsaParams = new RSAWithRSAParameterKey();

            rsaParams.AssignNewKey();

            Console.WriteLine("Hybrid Encryption with Integrity Check Demonstration in .NET");
            Console.WriteLine("------------------------------------------------------------");
            Console.WriteLine();

            try
            {
                var encryptedBlock = hybrid.EncryptData(Encoding.UTF8.GetBytes(original), rsaParams);
                var decrypted      = hybrid.DecryptData(encryptedBlock, rsaParams);

                Console.WriteLine("Original Message = " + original);
                Console.WriteLine();
                Console.WriteLine("Message After Decryption = " + Encoding.UTF8.GetString(decrypted));
            }
            catch (CryptographicException ex)
            {
                Console.WriteLine("Error : " + ex.Message);
            }
        }
Exemple #2
0
        public static void HyrbidEncrypDecrypt()
        {
            const string original = "Very secret and important information that can not into the hacker.";

            var rsaParams = new RSAWithRSAParameterKey();

            rsaParams.AssignNewKey();

            var hybrid = new HybridEncryption();

            var encryptedBlock = hybrid.EncryptData(Encoding.UTF8.GetBytes(original), rsaParams);
            var decrypted      = hybrid.DecryptData(encryptedBlock, rsaParams);

            Console.WriteLine("Hybrid Encryption Demonstration in .NET");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
            Console.WriteLine("Original Message = " + original);
            Console.WriteLine();
            Console.WriteLine("Message After Decruption = " + Encoding.UTF8.GetString(decrypted));
        }
Exemple #3
0
        public static void EncryptDecryptWithRSAWithRSAParameterKey()
        {
            var          rsaParams = new RSAWithRSAParameterKey();
            const string original  = "Text to encrypt";

            rsaParams.AssignNewKey();

            var encryptedRsaParams = rsaParams.EncryptData(Encoding.UTF8.GetBytes(original));
            var decryptedRsaParams = rsaParams.DecryptData(encryptedRsaParams);

            Console.WriteLine("RSA Encryption Demonstration in .NET");
            Console.WriteLine("------------------------------------");
            Console.WriteLine();
            Console.WriteLine("In Memory Key");
            Console.WriteLine();
            Console.WriteLine("Original Text = " + original);
            Console.WriteLine();
            Console.WriteLine("Encrypted Text = " + Convert.ToBase64String(encryptedRsaParams));
            Console.WriteLine();
            Console.WriteLine("Decrypted Text = " + Encoding.Default.GetString(decryptedRsaParams));
            Console.WriteLine();
            Console.WriteLine();
        }