public void Pem() { if (Environment.OSVersion.Platform == PlatformID.Unix) return; // No DLLs on Unix // TODO: Conditional compilation for mono compability string publicKeyPem = Encoding.ASCII.GetString(Resources.GetResource("RSACryptoServiceProviderExtensionPublicKey.pem")); string privateKeyPem = Encoding.ASCII.GetString(Resources.GetResource("RSACryptoServiceProviderExtensionPrivateKey.pem")); Console.WriteLine("Public key:\n{0}", publicKeyPem); Console.WriteLine("Private key:\n{0}", privateKeyPem); byte[] signature; using (var rsa = new RSACryptoServiceProvider()) { rsa.PersistKeyInCsp = false; rsa.ImportPrivateKeyPem(privateKeyPem); using (var sha1 = new SHA1CryptoServiceProvider()) signature = rsa.SignData(DataToSign, sha1); } using (var rsa = new RSACryptoServiceProvider()) { rsa.PersistKeyInCsp = false; rsa.ImportPublicKeyPem(publicKeyPem); bool isValid; using (var sha1 = new SHA1CryptoServiceProvider()) isValid = rsa.VerifyData(DataToSign, sha1, signature); Assert.IsTrue(isValid); // invalidate signature so the next check must fail signature[signature.Length - 1] ^= 0xFF; using (var sha1 = new SHA1CryptoServiceProvider()) isValid = rsa.VerifyData(DataToSign, sha1, signature); Assert.IsFalse(isValid); } }