Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Security / Cryptography / CngProvider.cs / 1305376 / CngProvider.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
namespace System.Security.Cryptography {
///
/// Utility class to strongly type providers used with CNG. Since all CNG APIs which require a
/// provider name take the name as a string, we use this string wrapper class to specifically mark
/// which parameters are expected to be providers. We also provide a list of well known provider
/// names, which helps Intellisense users find a set of good providernames to use.
///
[Serializable]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public sealed class CngProvider : IEquatable {
private static CngProvider s_msSmartCardKsp;
private static CngProvider s_msSoftwareKsp;
private string m_provider;
public CngProvider(string provider) {
Contract.Ensures(!String.IsNullOrEmpty(m_provider));
if (provider == null) {
throw new ArgumentNullException("provider");
}
if (provider.Length == 0) {
throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidProviderName, provider), "provider");
}
m_provider = provider;
}
///
/// Name of the CNG provider
///
public string Provider {
get {
Contract.Ensures(!String.IsNullOrEmpty(Contract.Result()));
return m_provider;
}
}
public static bool operator ==(CngProvider left, CngProvider right) {
if (Object.ReferenceEquals(left, null)) {
return Object.ReferenceEquals(right, null);
}
return left.Equals(right);
}
[Pure]
public static bool operator !=(CngProvider left, CngProvider right) {
if (Object.ReferenceEquals(left, null)) {
return !Object.ReferenceEquals(right, null);
}
return !left.Equals(right);
}
public override bool Equals(object obj) {
Contract.Assert(m_provider != null);
return Equals(obj as CngProvider);
}
public bool Equals(CngProvider other) {
if (Object.ReferenceEquals(other, null)) {
return false;
}
return m_provider.Equals(other.Provider);
}
public override int GetHashCode() {
Contract.Assert(m_provider != null);
return m_provider.GetHashCode();
}
public override string ToString() {
Contract.Assert(m_provider != null);
return m_provider.ToString();
}
//
// Well known NCrypt KSPs
//
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "CardKey", Justification = "This is not 'Smart Cardkey', but 'Smart Card Key'")]
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "SmartCard", Justification = "Smart Card is two words in the ncrypt usage")]
public static CngProvider MicrosoftSmartCardKeyStorageProvider {
get {
Contract.Ensures(Contract.Result() != null);
if (s_msSmartCardKsp == null) {
s_msSmartCardKsp = new CngProvider("Microsoft Smart Card Key Storage Provider"); // MS_SMART_CARD_KEY_STORAGE_PROVIDER
}
return s_msSmartCardKsp;
}
}
public static CngProvider MicrosoftSoftwareKeyStorageProvider {
get {
Contract.Ensures(Contract.Result() != null);
if (s_msSoftwareKsp == null) {
s_msSoftwareKsp = new CngProvider("Microsoft Software Key Storage Provider"); // MS_KEY_STORAGE_PROVIDER
}
return s_msSoftwareKsp;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
namespace System.Security.Cryptography {
///
/// Utility class to strongly type providers used with CNG. Since all CNG APIs which require a
/// provider name take the name as a string, we use this string wrapper class to specifically mark
/// which parameters are expected to be providers. We also provide a list of well known provider
/// names, which helps Intellisense users find a set of good providernames to use.
///
[Serializable]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public sealed class CngProvider : IEquatable {
private static CngProvider s_msSmartCardKsp;
private static CngProvider s_msSoftwareKsp;
private string m_provider;
public CngProvider(string provider) {
Contract.Ensures(!String.IsNullOrEmpty(m_provider));
if (provider == null) {
throw new ArgumentNullException("provider");
}
if (provider.Length == 0) {
throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidProviderName, provider), "provider");
}
m_provider = provider;
}
///
/// Name of the CNG provider
///
public string Provider {
get {
Contract.Ensures(!String.IsNullOrEmpty(Contract.Result()));
return m_provider;
}
}
public static bool operator ==(CngProvider left, CngProvider right) {
if (Object.ReferenceEquals(left, null)) {
return Object.ReferenceEquals(right, null);
}
return left.Equals(right);
}
[Pure]
public static bool operator !=(CngProvider left, CngProvider right) {
if (Object.ReferenceEquals(left, null)) {
return !Object.ReferenceEquals(right, null);
}
return !left.Equals(right);
}
public override bool Equals(object obj) {
Contract.Assert(m_provider != null);
return Equals(obj as CngProvider);
}
public bool Equals(CngProvider other) {
if (Object.ReferenceEquals(other, null)) {
return false;
}
return m_provider.Equals(other.Provider);
}
public override int GetHashCode() {
Contract.Assert(m_provider != null);
return m_provider.GetHashCode();
}
public override string ToString() {
Contract.Assert(m_provider != null);
return m_provider.ToString();
}
//
// Well known NCrypt KSPs
//
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "CardKey", Justification = "This is not 'Smart Cardkey', but 'Smart Card Key'")]
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "SmartCard", Justification = "Smart Card is two words in the ncrypt usage")]
public static CngProvider MicrosoftSmartCardKeyStorageProvider {
get {
Contract.Ensures(Contract.Result() != null);
if (s_msSmartCardKsp == null) {
s_msSmartCardKsp = new CngProvider("Microsoft Smart Card Key Storage Provider"); // MS_SMART_CARD_KEY_STORAGE_PROVIDER
}
return s_msSmartCardKsp;
}
}
public static CngProvider MicrosoftSoftwareKeyStorageProvider {
get {
Contract.Ensures(Contract.Result() != null);
if (s_msSoftwareKsp == null) {
s_msSoftwareKsp = new CngProvider("Microsoft Software Key Storage Provider"); // MS_KEY_STORAGE_PROVIDER
}
return s_msSoftwareKsp;
}
}
}
}
// 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
- StackSpiller.Bindings.cs
- HTTPNotFoundHandler.cs
- URL.cs
- HttpApplicationStateBase.cs
- XamlReaderConstants.cs
- ProcessHostConfigUtils.cs
- DataControlExtensions.cs
- GridPattern.cs
- CultureTableRecord.cs
- UserPreferenceChangingEventArgs.cs
- ConfigXmlElement.cs
- TextAutomationPeer.cs
- InvalidStoreProtectionKeyException.cs
- AssemblyFilter.cs
- PageThemeCodeDomTreeGenerator.cs
- WinEventTracker.cs
- CodePropertyReferenceExpression.cs
- XXXInfos.cs
- WindowProviderWrapper.cs
- Guid.cs
- TreeNodeSelectionProcessor.cs
- TcpClientChannel.cs
- BufferBuilder.cs
- XmlAggregates.cs
- XmlQuerySequence.cs
- WrappedIUnknown.cs
- StreamWriter.cs
- OperationAbortedException.cs
- Image.cs
- ColorMatrix.cs
- DataTransferEventArgs.cs
- DependencyObjectType.cs
- Sql8ConformanceChecker.cs
- HatchBrush.cs
- SQLChars.cs
- Triplet.cs
- RepeatInfo.cs
- SectionRecord.cs
- WebPartHeaderCloseVerb.cs
- BaseResourcesBuildProvider.cs
- SizeLimitedCache.cs
- DataError.cs
- PieceDirectory.cs
- X509PeerCertificateAuthentication.cs
- FormDocumentDesigner.cs
- CircleHotSpot.cs
- SchemaImporterExtension.cs
- SymbolPair.cs
- UnsafeCollabNativeMethods.cs
- GPStream.cs
- CompositeDataBoundControl.cs
- FileDialogPermission.cs
- RectangleF.cs
- _OverlappedAsyncResult.cs
- ChildTable.cs
- DetectEofStream.cs
- Journal.cs
- InvokeBinder.cs
- CalendarDateChangedEventArgs.cs
- Control.cs
- Trace.cs
- ApplicationActivator.cs
- HttpCacheVary.cs
- BuilderPropertyEntry.cs
- basemetadatamappingvisitor.cs
- DocumentGridPage.cs
- DataGridLinkButton.cs
- AsymmetricAlgorithm.cs
- Int32Converter.cs
- SecurityKeyIdentifier.cs
- Module.cs
- FilterQuery.cs
- SecurityKeyUsage.cs
- OleDbPermission.cs
- Popup.cs
- webeventbuffer.cs
- HScrollBar.cs
- MergeFailedEvent.cs
- dataobject.cs
- PictureBox.cs
- DataGridViewAutoSizeModeEventArgs.cs
- LinkButton.cs
- HostingEnvironmentSection.cs
- ItemContainerGenerator.cs
- TextServicesContext.cs
- Crc32.cs
- SystemException.cs
- StorageMappingItemCollection.cs
- ClientBuildManager.cs
- __Filters.cs
- XmlConvert.cs
- PresentationAppDomainManager.cs
- CodeFieldReferenceExpression.cs
- XmlLanguageConverter.cs
- ObfuscationAttribute.cs
- _NetworkingPerfCounters.cs
- SimpleBitVector32.cs
- HwndPanningFeedback.cs
- WindowsAuthenticationModule.cs
- Overlapped.cs