Created
June 8, 2017 19:23
-
-
Save Clancey/dafac69f49c2e00dfe91ec57642499d8 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
public static string SignES256(string privateKey, string header, string payload) | |
{ | |
CngKey key = CngKey.Import( | |
Convert.FromBase64String(privateKey), | |
CngKeyBlobFormat.Pkcs8PrivateBlob); | |
using (ECDsaCng dsa = new ECDsaCng(key)) | |
{ | |
dsa.HashAlgorithm = CngAlgorithm.Sha256; | |
var unsignedJwtData = | |
Encode(Encoding.UTF8.GetBytes(header)) + "." + Encode(Encoding.UTF8.GetBytes(payload)); | |
var signature = | |
dsa.SignData(Encoding.UTF8.GetBytes(unsignedJwtData)); | |
return unsignedJwtData + "." + Encode(signature); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment