Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marzvrover/f654a6ad9a4743a1e60d89537093ea6a to your computer and use it in GitHub Desktop.
Save marzvrover/f654a6ad9a4743a1e60d89537093ea6a to your computer and use it in GitHub Desktop.
// <PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
string payload = @"[{""token"":""some_token"",""type"":""some_type"",""url"":""some_url"",""source"":""some_source""}]";
string signature = "MEUCIFLZzeK++IhS+y276SRk2Pe5LfDrfvTXu6iwKKcFGCrvAiEAhHN2kDOhy2I6eGkOFmxNkOJ+L2y8oQ9A2T9GGJo6WJY=";
string pubKey = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsz9ugWDj5jK5ELBK42ynytbo38gPHzZFI03Exwz8Lh/tCfL3YxwMdLjB+bMznsanlhK0RwcGP3IDb34kQDIo3Q==\n-----END PUBLIC KEY-----\n";
var encodedPayload = Encoding.UTF8.GetBytes(payload);
var encodedSignature = Convert.FromBase64String(signature);
using (var textReader = new StringReader(pubKey))
{
var parameter = (ECPublicKeyParameters)new PemReader(textReader).ReadObject();
ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA");
signer.Init(false, parameter);
signer.BlockUpdate(encodedPayload, 0, encodedPayload.Length);
Console.WriteLine(signer.VerifySignature(encodedSignature));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment