private static void TestHybridWithIntegrityAndSignatures() { const string original = "Very secret and important information that must not fall in the hands of the enemy."; var rsaParams = new RSAWithRSAParameterKey(); rsaParams.AssignNewKey(); var fullHybridEncryption = new FullHybridEncryption(); var digitalSignature = new DigitalSignatureFuncs(); digitalSignature.AssignNewKey(); try { var encryptedBlock = fullHybridEncryption.EncryptData(Encoding.UTF8.GetBytes(original), rsaParams, digitalSignature); var decryptedBlock = fullHybridEncryption.DecryptData(encryptedBlock, rsaParams, digitalSignature); Console.WriteLine($"Original Message: {original}"); Console.WriteLine($"Encrypted Block Data: {Convert.ToBase64String(encryptedBlock.EncryptedData)}"); Console.WriteLine($"Decrypted Block: {Convert.ToBase64String(decryptedBlock)}"); Console.WriteLine($"Decrypted Message: {Encoding.UTF8.GetString(decryptedBlock)}"); } catch (CryptographicException ex) { Console.WriteLine($"Cryptographic Exception occured: {ex.Message}"); } }
private static void TestRSAWithRSAParameterKey() { 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($"Original Text: {original}"); Console.WriteLine($"Encrypted RSA Params: {Convert.ToBase64String(encryptedRSAParams)}"); Console.WriteLine($"Decrypted RSA Params: {Convert.ToBase64String(decryptedRSAParams)}"); Console.WriteLine($"Decrypted Text: {Encoding.Default.GetString(decryptedRSAParams)}"); }
private static void TestHybrid() { const string original = "Very secret and important information that must not fall in the hands of the enemy."; var rsaParams = new RSAWithRSAParameterKey(); rsaParams.AssignNewKey(); var hybrid = new HybridEncryption(); var encryptedBlock = hybrid.EncryptData(Encoding.UTF8.GetBytes(original), rsaParams); var decryptedBlock = hybrid.DecryptData(encryptedBlock, rsaParams); Console.WriteLine($"Original Message: {original}"); Console.WriteLine($"Encrypted Block Data: {Convert.ToBase64String(encryptedBlock.EncryptedData)}"); Console.WriteLine($"Decrypted Block: {Convert.ToBase64String(decryptedBlock)}"); Console.WriteLine($"Decrypted Message: {Encoding.UTF8.GetString(decryptedBlock)}"); }