Skip to content

Instantly share code, notes, and snippets.

@jstedfast
Created June 3, 2016 18:47
Show Gist options
  • Save jstedfast/21edcba5171ace6f4682c5acd3da3f69 to your computer and use it in GitHub Desktop.
Save jstedfast/21edcba5171ace6f4682c5acd3da3f69 to your computer and use it in GitHub Desktop.
How to load a DKIM public key from a string
using System;
using System.IO;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.OpenSsl;
namespace DkimKeyLocatorExample
{
public class Program
{
public static void Main (string[] args)
{
string gmailDkimKey = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Kd87/UeJjenpabgbFwh+
eBCsSTrqmwIYYvywlbhbqoo2DymndFkbjOVIPIldNs/m40KF+yzMn1skyoxcTUGCQs8g3FgD2A
p3ZB5DekAo5wMmk4wimDO+U8QzI3SD07y2+07wlNWwIt8svnxgdxGkVbbhzY8i+RQ9DpSVpPbF
7ykQxtKXkv/ahW3KjViiAH+ghvvIhkx4xYSIc9oSwVmAl5OctMEeWUwg8Istjqz8BZeTWbf41f
bNhte7Y+YqZOwq1Sd0DbvYAD9NOZK9vlfuac0598HY+vtSBczUiKERHv1yRbcaQtZFh5wtiRrN
04BLUTD21MycBX5jYchHjPY/wIDAQAB
-----END PUBLIC KEY-----
";
AsymmetricKeyParameter key;
using (var stream = new StringReader (gmailDkimKey)) {
var reader = new PemReader (stream);
key = reader.ReadObject () as AsymmetricKeyParameter;
}
Console.WriteLine (key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment