public void EncryptWithPrivatePemTest() { var pem = File.ReadAllText(Path.Join(path, @"Data\certificate.pem")) + File.ReadAllText(Path.Join(path, @"Data\private.pem")); var rsa = Asymmetric.FromPem(pem); var cipher = rsa.Encrypt("Attack at dawn!"); Assert.AreEqual("Attack at dawn!", rsa.Decrypt(cipher)); }
public void VerifyUsingPublicPemTest() { // Create a signature with the PFX file. var signature = new Asymmetric(Path.Join(path, @"Data\certificate.pfx"), password).Sign(message.ToBytes()); // Use the PEM certificate to verify the signature. var pem = File.ReadAllText(Path.Join(path, @"Data\certificate.pem")); var rsa = Asymmetric.FromPem(pem); Assert.IsTrue(rsa.Verify(message.ToBytes(), signature)); Assert.IsTrue(rsa.Verify(message.ToBytes(), signatureBase64.FromBase64())); // We should not be allowed to sign with just a public key. Assert.ThrowsException <Exception>(() => { rsa.Sign(message.ToBytes()); }); }