Created
June 9, 2019 01:37
-
-
Save drawcode/5947782f268c6491c6c693cccc991730 to your computer and use it in GitHub Desktop.
RSAPKCS1SHA256SignatureDescription.cs
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
using System.Security.Cryptography; | |
namespace Sample | |
{ | |
/// <summary> | |
/// SignatureDescription impl for http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 | |
/// </summary> | |
public class RSAPKCS1SHA256SignatureDescription : SignatureDescription | |
{ | |
/// <summary> | |
/// Registers the http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 algorithm | |
/// with the .NET CrytoConfig registry. This needs to be called once per | |
/// appdomain before attempting to validate SHA256 signatures. | |
/// </summary> | |
public static void Register() | |
{ | |
CryptoConfig.AddAlgorithm( | |
typeof(RSAPKCS1SHA256SignatureDescription), | |
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); | |
} | |
/// <summary> | |
/// .NET calls this parameterless ctor | |
/// </summary> | |
public RSAPKCS1SHA256SignatureDescription() | |
{ | |
KeyAlgorithm = "System.Security.Cryptography.RSACryptoServiceProvider"; | |
DigestAlgorithm = "System.Security.Cryptography.SHA256Managed"; | |
FormatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureFormatter"; | |
DeformatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureDeformatter"; | |
} | |
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) | |
{ | |
var asymmetricSignatureDeformatter = | |
(AsymmetricSignatureDeformatter)CryptoConfig.CreateFromName(DeformatterAlgorithm); | |
asymmetricSignatureDeformatter.SetKey(key); | |
asymmetricSignatureDeformatter.SetHashAlgorithm("SHA256"); | |
return asymmetricSignatureDeformatter; | |
} | |
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) | |
{ | |
var asymmetricSignatureFormatter = | |
(AsymmetricSignatureFormatter)CryptoConfig.CreateFromName(FormatterAlgorithm); | |
asymmetricSignatureFormatter.SetKey(key); | |
asymmetricSignatureFormatter.SetHashAlgorithm("SHA256"); | |
return asymmetricSignatureFormatter; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment