Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / ManagedLibraries / Security / System / Security / Cryptography / Pkcs / Pkcs7Signer.cs / 1 / Pkcs7Signer.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// Pkcs7Signer.cs
//
namespace System.Security.Cryptography.Pkcs {
using System.Globalization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public sealed class CmsSigner {
private SubjectIdentifierType m_signerIdentifierType;
private X509Certificate2 m_certificate;
private Oid m_digestAlgorithm;
private CryptographicAttributeObjectCollection m_signedAttributes;
private CryptographicAttributeObjectCollection m_unsignedAttributes;
private X509Certificate2Collection m_certificates;
private X509IncludeOption m_includeOption;
private bool m_dummyCert;
//
// Constructors.
//
public CmsSigner () : this(SubjectIdentifierType.IssuerAndSerialNumber, null) {}
public CmsSigner (SubjectIdentifierType signerIdentifierType) : this (signerIdentifierType, null) {}
public CmsSigner (X509Certificate2 certificate) : this(SubjectIdentifierType.IssuerAndSerialNumber, certificate) {}
public CmsSigner (CspParameters parameters) : this(SubjectIdentifierType.SubjectKeyIdentifier,
PkcsUtils.CreateDummyCertificate(parameters)) {
m_dummyCert = true;
this.IncludeOption = X509IncludeOption.None;
}
public CmsSigner (SubjectIdentifierType signerIdentifierType, X509Certificate2 certificate) {
switch (signerIdentifierType) {
case SubjectIdentifierType.Unknown:
this.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
case SubjectIdentifierType.IssuerAndSerialNumber:
this.SignerIdentifierType = signerIdentifierType;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
case SubjectIdentifierType.SubjectKeyIdentifier:
this.SignerIdentifierType = signerIdentifierType;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
case SubjectIdentifierType.NoSignature:
this.SignerIdentifierType = signerIdentifierType;
this.IncludeOption = X509IncludeOption.None;
break;
default:
this.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
}
this.Certificate = certificate;
this.DigestAlgorithm = new Oid(CAPI.szOID_OIWSEC_sha1);
m_signedAttributes = new CryptographicAttributeObjectCollection();
m_unsignedAttributes = new CryptographicAttributeObjectCollection();
m_certificates = new X509Certificate2Collection();
}
//
// Public APIs.
//
public SubjectIdentifierType SignerIdentifierType {
get {
return m_signerIdentifierType;
}
set {
if (value != SubjectIdentifierType.IssuerAndSerialNumber &&
value != SubjectIdentifierType.SubjectKeyIdentifier &&
value != SubjectIdentifierType.NoSignature)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), "value"));
if (m_dummyCert && value != SubjectIdentifierType.SubjectKeyIdentifier)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), "value"));
m_signerIdentifierType = value;
}
}
public X509Certificate2 Certificate {
get {
return m_certificate;
}
set {
m_certificate = value;
}
}
public Oid DigestAlgorithm {
get {
return m_digestAlgorithm;
}
set {
m_digestAlgorithm = value;
}
}
public CryptographicAttributeObjectCollection SignedAttributes {
get {
return m_signedAttributes;
}
}
public CryptographicAttributeObjectCollection UnsignedAttributes {
get {
return m_unsignedAttributes;
}
}
public X509Certificate2Collection Certificates {
get {
return m_certificates;
}
}
public X509IncludeOption IncludeOption {
get {
return m_includeOption;
}
set {
if (value < X509IncludeOption.None || value > X509IncludeOption.WholeChain)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), "value"));
m_includeOption = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// Pkcs7Signer.cs
//
namespace System.Security.Cryptography.Pkcs {
using System.Globalization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public sealed class CmsSigner {
private SubjectIdentifierType m_signerIdentifierType;
private X509Certificate2 m_certificate;
private Oid m_digestAlgorithm;
private CryptographicAttributeObjectCollection m_signedAttributes;
private CryptographicAttributeObjectCollection m_unsignedAttributes;
private X509Certificate2Collection m_certificates;
private X509IncludeOption m_includeOption;
private bool m_dummyCert;
//
// Constructors.
//
public CmsSigner () : this(SubjectIdentifierType.IssuerAndSerialNumber, null) {}
public CmsSigner (SubjectIdentifierType signerIdentifierType) : this (signerIdentifierType, null) {}
public CmsSigner (X509Certificate2 certificate) : this(SubjectIdentifierType.IssuerAndSerialNumber, certificate) {}
public CmsSigner (CspParameters parameters) : this(SubjectIdentifierType.SubjectKeyIdentifier,
PkcsUtils.CreateDummyCertificate(parameters)) {
m_dummyCert = true;
this.IncludeOption = X509IncludeOption.None;
}
public CmsSigner (SubjectIdentifierType signerIdentifierType, X509Certificate2 certificate) {
switch (signerIdentifierType) {
case SubjectIdentifierType.Unknown:
this.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
case SubjectIdentifierType.IssuerAndSerialNumber:
this.SignerIdentifierType = signerIdentifierType;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
case SubjectIdentifierType.SubjectKeyIdentifier:
this.SignerIdentifierType = signerIdentifierType;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
case SubjectIdentifierType.NoSignature:
this.SignerIdentifierType = signerIdentifierType;
this.IncludeOption = X509IncludeOption.None;
break;
default:
this.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
this.IncludeOption = X509IncludeOption.ExcludeRoot;
break;
}
this.Certificate = certificate;
this.DigestAlgorithm = new Oid(CAPI.szOID_OIWSEC_sha1);
m_signedAttributes = new CryptographicAttributeObjectCollection();
m_unsignedAttributes = new CryptographicAttributeObjectCollection();
m_certificates = new X509Certificate2Collection();
}
//
// Public APIs.
//
public SubjectIdentifierType SignerIdentifierType {
get {
return m_signerIdentifierType;
}
set {
if (value != SubjectIdentifierType.IssuerAndSerialNumber &&
value != SubjectIdentifierType.SubjectKeyIdentifier &&
value != SubjectIdentifierType.NoSignature)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), "value"));
if (m_dummyCert && value != SubjectIdentifierType.SubjectKeyIdentifier)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), "value"));
m_signerIdentifierType = value;
}
}
public X509Certificate2 Certificate {
get {
return m_certificate;
}
set {
m_certificate = value;
}
}
public Oid DigestAlgorithm {
get {
return m_digestAlgorithm;
}
set {
m_digestAlgorithm = value;
}
}
public CryptographicAttributeObjectCollection SignedAttributes {
get {
return m_signedAttributes;
}
}
public CryptographicAttributeObjectCollection UnsignedAttributes {
get {
return m_unsignedAttributes;
}
}
public X509Certificate2Collection Certificates {
get {
return m_certificates;
}
}
public X509IncludeOption IncludeOption {
get {
return m_includeOption;
}
set {
if (value < X509IncludeOption.None || value > X509IncludeOption.WholeChain)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), "value"));
m_includeOption = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TryLoadRunnableWorkflowCommand.cs
- FormViewRow.cs
- RelationshipEnd.cs
- HttpListenerContext.cs
- IndentedWriter.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- MediaContextNotificationWindow.cs
- RefreshEventArgs.cs
- AssociationType.cs
- XsltSettings.cs
- ExpressionBuilderContext.cs
- StatusBarItem.cs
- ErrorWebPart.cs
- RequestNavigateEventArgs.cs
- InstanceData.cs
- StringArrayConverter.cs
- TableRowGroupCollection.cs
- InputLangChangeRequestEvent.cs
- XmlSerializationGeneratedCode.cs
- TextServicesDisplayAttribute.cs
- ExtensionsSection.cs
- precedingquery.cs
- X509Utils.cs
- ToolBarPanel.cs
- Mapping.cs
- WsrmMessageInfo.cs
- DataGridViewRowStateChangedEventArgs.cs
- DataGridAddNewRow.cs
- panel.cs
- HandoffBehavior.cs
- HttpListenerContext.cs
- Exception.cs
- RemoteWebConfigurationHost.cs
- DependentTransaction.cs
- RenderOptions.cs
- RawStylusActions.cs
- login.cs
- MetadataArtifactLoaderFile.cs
- EventData.cs
- ResolveNameEventArgs.cs
- AncestorChangedEventArgs.cs
- X509SecurityTokenProvider.cs
- AssemblySettingAttributes.cs
- Floater.cs
- InvalidateEvent.cs
- CheckedListBox.cs
- BinarySerializer.cs
- WsdlWriter.cs
- PublisherIdentityPermission.cs
- DesignUtil.cs
- OdbcInfoMessageEvent.cs
- GlyphElement.cs
- ProfilePropertyMetadata.cs
- SubclassTypeValidatorAttribute.cs
- WizardForm.cs
- StackOverflowException.cs
- HttpGetServerProtocol.cs
- LineMetrics.cs
- OleDbCommand.cs
- WebPartActionVerb.cs
- EasingFunctionBase.cs
- WebPartZoneDesigner.cs
- IpcChannelHelper.cs
- EpmCustomContentSerializer.cs
- CompoundFileStreamReference.cs
- RadioButtonList.cs
- CompositionAdorner.cs
- ReferentialConstraintRoleElement.cs
- SingleObjectCollection.cs
- documentsequencetextcontainer.cs
- SqlMethodAttribute.cs
- WindowsListViewScroll.cs
- ButtonAutomationPeer.cs
- CommonObjectSecurity.cs
- MetadataExchangeBindings.cs
- XmlSchemaChoice.cs
- UTF32Encoding.cs
- IgnoreDataMemberAttribute.cs
- CompModSwitches.cs
- EntityDataSource.cs
- StreamProxy.cs
- CharKeyFrameCollection.cs
- BindingContext.cs
- OleDbDataReader.cs
- CollectionsUtil.cs
- HtmlImage.cs
- SemaphoreSecurity.cs
- AssemblyInfo.cs
- ObjectDataSourceEventArgs.cs
- HttpBindingExtension.cs
- DebugController.cs
- ExternalDataExchangeClient.cs
- DataGridViewHeaderCell.cs
- OracleConnectionString.cs
- StylusPointPropertyInfo.cs
- WindowsStatic.cs
- ScrollBar.cs
- MessageAction.cs
- URLEditor.cs
- LogReservationCollection.cs