Created
March 4, 2016 19:10
-
-
Save OllieJones/9b20b7bb010709e716fa to your computer and use it in GitHub Desktop.
Add this code to your dotnet app to enable rsa-sha256, rsa-384, and rsa-512 signatures.
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
/// <summary>Declare the signature type for rsa-sha512</summary> | |
public class RsaPkCs1Sha512SignatureDescription : SignatureDescription | |
{ | |
public RsaPkCs1Sha512SignatureDescription() | |
{ | |
KeyAlgorithm = typeof(RSACryptoServiceProvider).FullName; | |
DigestAlgorithm = typeof(SHA512CryptoServiceProvider).FullName; | |
FormatterAlgorithm = typeof(RSAPKCS1SignatureFormatter).FullName; | |
DeformatterAlgorithm = typeof(RSAPKCS1SignatureDeformatter).FullName; | |
} | |
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) | |
{ | |
var sigProcessor = (AsymmetricSignatureDeformatter)CryptoConfig.CreateFromName(DeformatterAlgorithm); | |
sigProcessor.SetKey(key); | |
sigProcessor.SetHashAlgorithm("SHA512"); | |
return sigProcessor; | |
} | |
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) | |
{ | |
var sigProcessor = | |
(AsymmetricSignatureFormatter)CryptoConfig.CreateFromName(FormatterAlgorithm); | |
sigProcessor.SetKey(key); | |
sigProcessor.SetHashAlgorithm("SHA512"); | |
return sigProcessor; | |
} | |
} | |
/// <summary>Declare the signature type for rsa-sha384</summary> | |
public class RsaPkCs1Sha384SignatureDescription : SignatureDescription { | |
public RsaPkCs1Sha384SignatureDescription() | |
{ | |
KeyAlgorithm = typeof(RSACryptoServiceProvider).FullName; | |
DigestAlgorithm = typeof(SHA384CryptoServiceProvider).FullName; | |
FormatterAlgorithm = typeof(RSAPKCS1SignatureFormatter).FullName; | |
DeformatterAlgorithm = typeof(RSAPKCS1SignatureDeformatter).FullName; | |
} | |
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) | |
{ | |
var sigProcessor = (AsymmetricSignatureDeformatter) CryptoConfig.CreateFromName(DeformatterAlgorithm); | |
sigProcessor.SetKey(key); | |
sigProcessor.SetHashAlgorithm("SHA384"); | |
return sigProcessor; | |
} | |
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) | |
{ | |
var sigProcessor = | |
(AsymmetricSignatureFormatter)CryptoConfig.CreateFromName(FormatterAlgorithm); | |
sigProcessor.SetKey(key); | |
sigProcessor.SetHashAlgorithm("SHA384"); | |
return sigProcessor; | |
} | |
} | |
/// <summary>Declare the signature type for rsa-sha256</summary> | |
public class RsaPkCs1Sha256SignatureDescription : SignatureDescription | |
{ | |
public RsaPkCs1Sha256SignatureDescription() | |
{ | |
KeyAlgorithm = typeof(RSACryptoServiceProvider).FullName; | |
DigestAlgorithm = typeof(SHA256CryptoServiceProvider).FullName; | |
FormatterAlgorithm = typeof(RSAPKCS1SignatureFormatter).FullName; | |
DeformatterAlgorithm = typeof(RSAPKCS1SignatureDeformatter).FullName; | |
} | |
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) | |
{ | |
var sigProcessor = | |
(AsymmetricSignatureDeformatter) CryptoConfig.CreateFromName(DeformatterAlgorithm); | |
sigProcessor.SetKey(key); | |
sigProcessor.SetHashAlgorithm("SHA256"); | |
return sigProcessor; | |
} | |
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) | |
{ | |
var sigProcessor = | |
(AsymmetricSignatureFormatter)CryptoConfig.CreateFromName(FormatterAlgorithm); | |
sigProcessor.SetKey(key); | |
sigProcessor.SetHashAlgorithm("SHA256"); | |
return sigProcessor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment