-
-
Save njmube/430e4002055caa4f740b to your computer and use it in GitHub Desktop.
This file contains 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
// signature | |
var signature = headerEncoded + "." + claimEncoded; | |
var signatureBytes = Encoding.UTF8.GetBytes(signature); | |
var certificate = new X509Certificate2(privateKey, privateKeyPassword); | |
// sign signature using SHA256 with RSA | |
var rsa = (RSACryptoServiceProvider)certificate.PrivateKey; | |
// As of .NET 3.5 SP1 the CSP instance works with a provider of type PROV_RSA_AES | |
var cspParameters = new CspParameters | |
{ | |
KeyContainerName = rsa.CspKeyContainerInfo.KeyContainerName, | |
KeyNumber = rsa.CspKeyContainerInfo.KeyNumber == KeyNumber.Exchange ? 1 : 2 | |
}; | |
var rsaAes = new RSACryptoServiceProvider(cspParameters) { PersistKeyInCsp = false }; | |
var signatureSignedBytes = rsaAes.SignData(signatureBytes, CryptoConfig.MapNameToOID("SHA256")); | |
var signatureSignedAndEncoded = _base64Encoder.ToBase64UrlEncodedString(signatureSignedBytes); | |
var jwt = headerEncoded + "." + claimEncoded + "." + signatureSignedAndEncoded; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment