Pkcs7Signer.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // Pkcs7Signer.cs - System.Security.Cryptography.Pkcs.Pkcs7Signer
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. #if NET_1_2
  10. using System;
  11. using System.Security.Cryptography.X509Certificates;
  12. namespace System.Security.Cryptography.Pkcs {
  13. public sealed class Pkcs7Signer {
  14. private SubjectIdentifierType _signer;
  15. private X509CertificateEx _certificate;
  16. private Oid _digest;
  17. private X509IncludeOption _options;
  18. private Pkcs9AttributeCollection _auth;
  19. private Pkcs9AttributeCollection _unauth;
  20. // constructors
  21. public Pkcs7Signer ()
  22. {
  23. _signer = SubjectIdentifierType.IssuerAndSerialNumber;
  24. _digest = new Oid ("1.3.14.3.2.26");
  25. _options = X509IncludeOption.ExcludeRoot;
  26. _auth = new Pkcs9AttributeCollection ();
  27. _unauth = new Pkcs9AttributeCollection ();
  28. }
  29. public Pkcs7Signer (SubjectIdentifierType signerIdentifierType) : this ()
  30. {
  31. if (signerIdentifierType == SubjectIdentifierType.Unknown)
  32. _signer = SubjectIdentifierType.IssuerAndSerialNumber;
  33. else
  34. _signer = signerIdentifierType;
  35. }
  36. public Pkcs7Signer (SubjectIdentifierType signerIdentifierType, X509CertificateEx certificate)
  37. : this (signerIdentifierType)
  38. {
  39. // FIXME: compatibility with fx 1.2.3400.0
  40. // if (certificate == null)
  41. // throw new ArgumentNullException ("certificate");
  42. _certificate = certificate;
  43. }
  44. public Pkcs7Signer (X509CertificateEx certificate) : this ()
  45. {
  46. // FIXME: compatibility with fx 1.2.3400.0
  47. // if (certificate == null)
  48. // throw new ArgumentNullException ("certificate");
  49. _certificate = certificate;
  50. }
  51. // properties
  52. public Pkcs9AttributeCollection AuthenticatedAttributes {
  53. get { return _auth; }
  54. }
  55. public X509CertificateEx Certificate {
  56. get { return _certificate; }
  57. set { _certificate = value; }
  58. }
  59. public Oid DigestAlgorithm {
  60. get { return _digest; }
  61. set { _digest = value; }
  62. }
  63. public X509IncludeOption IncludeOption {
  64. get { return _options; }
  65. set { _options = value; }
  66. }
  67. public SubjectIdentifierType SignerIdentifierType {
  68. get { return _signer; }
  69. set {
  70. if (value == SubjectIdentifierType.Unknown)
  71. throw new ArgumentException ("value");
  72. _signer = value;
  73. }
  74. }
  75. public Pkcs9AttributeCollection UnauthenticatedAttributes {
  76. get { return _unauth; }
  77. }
  78. }
  79. }
  80. #endif