public void TestEncryption() { var keys = RSACipher.GenerateKeys(); var text = "test of encryption"; var encryptedText = RSACipher.EncryptString(keys, text); var decryptedText = RSACipher.DecryptString(keys, encryptedText); Assert.IsFalse(string.IsNullOrWhiteSpace(encryptedText)); Assert.IsFalse(string.IsNullOrWhiteSpace(decryptedText)); Assert.AreEqual(text, decryptedText); }
public void TestKeyLoadingAndEncrypting() { var privateKey = @" -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEA3BGLEjYSMZGI9EELAbq9/teH/EPA5aa+XTfOoe6PBRDmPIvl vCuy+u37DLDqry1zf5spaDSLYVMhiiLDcisLAb0n1TDOHTdSPMTWq7k9ACe0lPOT d0uPaFwWRBtKXdj/ZmzfEqkwMyUFGTQXeol6c4R3ddnp6fnkZKm1neI+cQ2emvrU FFbH1NsrC8Kb0F1ysBvePGIvpsf2xc42+pl6tkyhGdnu41Tg78qeYBJWJuxSgcqV /uq9RB5vwfAKefpQK25eyUXX1cFGOOOJk4ZKepVkKXYwrkjlg6YUczTeOd4ai0Z5 x28d8o3pDv44gd7g1nHmeHiMDePQSzW8kHWbtwIDAQABAoIBAGAS3Jb3uhufwJ15 o9d+ciHGcFyGK7lWgTbq/S+emRuKFCmMnZ/3p+x6ZqZUui/99LVZxMr0XYEArNzE bnTyK5z3umMNKn6Av0s+V8WiWeoua1y3tcJX32SdBy92hpHQATfzAbQA3sUFPWOS ZUmeqTGzO//cQY1fBgGYQWyK792kV+ZcgrfPprohuX4vMkZgiq9X8bSQZeyllnFl Ve5a3lBfehENN5T9oAO5Z79zskKczsuC8ENF8sue8y2hGVWcP1wxynl16N7a/Q7c 7ZBeeaEyzgbwaBD+uOqgRJ95+9aVSp0vv95lO4hevNvHzNjBcjnxZA1yul54qzpF 9s61RGkCgYEA+7zIa1HQv/B3YD1uDhuaUj3kKVr0gvFmUZ38OBWJWuvAO4Fp/Plh PNBpVdzBF+gxld0xjieEPYD86MYWNUZbXb/EL9tkWs5MRCuNPtHabXXc1KD6lO6h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gcqV /uq9RB5vwfAKefpQK25eyUXX1cFGOOOJk4ZKepVkKXYwrkjlg6YUczTeOd4ai0Z5 x28d8o3pDv44gd7g1nHmeHiMDePQSzW8kHWbtwIDAQABAgMBAAECAwEAAQIDAQAB AgMBAAECAwEAAQIDAQAB -----END PUBLIC KEY----- "; var keys = new RSAKeyPair(privateKey, publicKey); var text = "test of encryption"; var encryptedText = RSACipher.EncryptString(keys, text); var decryptedText = RSACipher.DecryptString(keys, encryptedText); Assert.IsFalse(string.IsNullOrWhiteSpace(encryptedText)); Assert.IsFalse(string.IsNullOrWhiteSpace(decryptedText)); Assert.AreEqual(text, decryptedText); }