X509SigningCredentials.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Security.Cryptography.X509Certificates;
  3. namespace System.IdentityModel.Tokens
  4. {
  5. public class X509SigningCredentials : SigningCredentials
  6. {
  7. public X509Certificate2 Certificate { get; private set; }
  8. public X509SigningCredentials (X509Certificate2 certificate)
  9. : this (certificate, X509SigningCredentials.GetSecurityKeyIdentifier (certificate), SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest)
  10. { }
  11. public X509SigningCredentials (X509Certificate2 certificate, SecurityKeyIdentifier ski)
  12. : this (certificate, ski, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest)
  13. { }
  14. public X509SigningCredentials (X509Certificate2 certificate, string signatureAlgorithm, string digestAlgorithm)
  15. : this (certificate, X509SigningCredentials.GetSecurityKeyIdentifier (certificate), signatureAlgorithm, digestAlgorithm)
  16. { }
  17. public X509SigningCredentials (X509Certificate2 certificate, SecurityKeyIdentifier ski, string signatureAlgorithm, string digestAlgorithm)
  18. : base (new X509SecurityToken (certificate).SecurityKeys[0], signatureAlgorithm, digestAlgorithm, ski)
  19. {
  20. Certificate = certificate;
  21. }
  22. private static SecurityKeyIdentifier GetSecurityKeyIdentifier (X509Certificate2 certificate) {
  23. return new SecurityKeyIdentifier (new X509SecurityToken (certificate).CreateKeyIdentifierClause<X509RawDataKeyIdentifierClause> ());
  24. }
  25. }
  26. }