Created
November 17, 2022 18:41
-
-
Save eddynaka/647dbd91b8c385e409ceb1fea97cea20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <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