本文整理汇总了C#中X509FindType类的典型用法代码示例。如果您正苦于以下问题:C# X509FindType类的具体用法?C# X509FindType怎么用?C# X509FindType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509FindType类属于命名空间,在下文中一共展示了X509FindType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFindValue
/// <summary>
/// Gets the find value.
/// </summary>
/// <param name="findType">Type of the find.</param>
/// <param name="value">The value.</param>
/// <returns>The find value formated as string.</returns>
public static string GetFindValue(X509FindType findType, X509Certificate2 value)
{
string findValue = null;
switch (findType)
{
case X509FindType.FindBySubjectDistinguishedName:
findValue = GetSubjectDistinguishedName(value.SubjectName.Name);
break;
case X509FindType.FindByThumbprint:
findValue = value.Thumbprint;
break;
case X509FindType.FindBySubjectName:
findValue = value.SubjectName.Name;
break;
case X509FindType.FindBySerialNumber:
findValue = value.SerialNumber;
break;
default:
findValue = value.ToString(false);
break;
}
return findValue;
}
示例2: Load
public static X509Certificate2 Load(StoreName name, StoreLocation location, X509FindType type, string findValue)
{
if (string.IsNullOrWhiteSpace(findValue))
throw new ArgumentNullException("findValue");
var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
try
{
var certificates = store.Certificates.Find(type, findValue, false);
if (certificates.Count != 1)
{
throw new InvalidOperationException(
string.Format(CultureInfo.InvariantCulture,
"Finding certificate with [StoreName:{0}, StoreLocation:{1}, X509FindType: {2}, FindValue: {3}] matched {4} certificates. A unique match is required.",
name, location, type, findValue, certificates.Count));
}
return certificates[0];
}
finally
{
store.Close();
}
}
示例3: FromStore
/// <summary>
/// Will deploy certificate found by find type and find value from the local certificate store, to remote certificate store on server.
/// </summary>
/// <param name="findType"></param>
/// <param name="findValue"></param>
/// <returns></returns>
public static IOfferRemoteConfiguration FromStore(this IOfferSslInfrastructure sslInfra, X509FindType findType, string findValue)
{
var infraBuilder = ((SslInfrastructureBuilder) sslInfra).InfrastructureBuilder;
var certOp = new CertificateFromStoreOperation(findType, findValue);
Configure.Operation(infraBuilder, certOp);
return infraBuilder;
}
示例4: TryResolveCertificate
internal static bool TryResolveCertificate(StoreName storeName, StoreLocation storeLocation, X509FindType findType, object findValue, out X509Certificate2 certificate)
{
X509Store store = new X509Store(storeName, storeLocation);
store.Open(OpenFlags.ReadOnly);
certificate = null;
X509Certificate2Collection certs = null;
X509Certificate2Collection matches = null;
try
{
certs = store.Certificates;
matches = certs.Find(findType, findValue, false);
// Throwing InvalidOperationException here, following WCF precedent.
// Might be worth introducing a more specific exception here.
if (matches.Count == 1)
{
certificate = new X509Certificate2(matches[0]);
return true;
}
}
finally
{
CryptoHelper.ResetAllCertificates(matches);
CryptoHelper.ResetAllCertificates(certs);
store.Close();
}
return false;
}
示例5: FromStore
public IOfferInfrastructure FromStore(X509FindType findType, string findValue)
{
var certOp = new CertificateFromStoreOperation(findType, findValue);
var compositeSequence = _infrastructureSequence.NewCompositeSequence(certOp);
certOp.Configure(new RemoteCompositeBuilder(compositeSequence, _webDeploy));
return _infrastructureBuilder;
}
示例6: LocalMachineCertificateFactory
/// <summary>
/// Initializes a new instance of the <see cref="LocalMachineCertificateFactory"/> class.
/// </summary>
/// <param name="certificateSubject">The certificate subject.</param>
/// <param name="findType"></param>
public LocalMachineCertificateFactory(string certificateSubject, X509FindType findType)
{
_certificateSubject = certificateSubject;
_findType = findType;
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
}
示例7: X509SecurityTokenProvider
public X509SecurityTokenProvider(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue)
{
if (findValue == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
}
X509CertificateStore store = new X509CertificateStore(storeName, storeLocation);
X509Certificate2Collection certificates = null;
try
{
store.Open(OpenFlags.ReadOnly);
certificates = store.Find(findType, findValue, false);
if (certificates.Count < 1)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.CannotFindCert, storeName, storeLocation, findType, findValue)));
}
if (certificates.Count > 1)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.FoundMultipleCerts, storeName, storeLocation, findType, findValue)));
}
this.certificate = new X509Certificate2(certificates[0]);
}
finally
{
SecurityUtils.ResetAllCertificates(certificates);
store.Close();
}
}
示例8: FetchCertificate
public FetchCertificate(X509FindType criteria, object match)
{
Criteria = criteria;
MatchesValue = match;
StoreLocation = StoreLocation.LocalMachine;
StoreName = StoreName.My;
}
示例9: SetCertificate
public void SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue)
{
if (findValue == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
}
ThrowIfImmutable();
var dotNetCertificate = SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
IReadOnlyList<Certificate> uwpCertificates;
try
{
uwpCertificates = GetCertificatesFromWinRTStore(dotNetCertificate);
}
catch (Exception)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(SecurityUtils.CreateCertificateLoadException(
storeName, storeLocation, findType, findValue, null, 0));
}
if (uwpCertificates.Count != 1)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(SecurityUtils.CreateCertificateLoadException(
storeName, storeLocation, findType, findValue, null, uwpCertificates.Count));
}
AttachUwpCertificate(dotNetCertificate, uwpCertificates[0]);
_certificate = dotNetCertificate;
}
示例10: CreateCustom
/// <summary>
/// Creates a custom certificate search directive, based on the specified find type and value.
/// </summary>
/// <param name="findType"></param>
/// <param name="findValue"></param>
/// <returns></returns>
public static CertificateSearchDirective CreateCustom(X509FindType findType, string findValue)
{
return new CertificateSearchDirective
{
FindType = findType,
FindValue = findValue
};
}
示例11: SecurityBehavior
public SecurityBehavior(ServiceSecurity mode,StoreLocation storeLocation,StoreName storeName,X509FindType findType,string subjectName)
{
m_Mode = mode;
m_StoreLocation = storeLocation;
m_StoreName = storeName;
m_FindType = findType;
m_SubjectName = subjectName;
}
示例12: Find
private IEnumerable<X509Certificate2> Find(X509FindType findType, string criteria, bool validOnly) {
try {
return _storeWrapper.Find(findType, criteria, validOnly);
} finally {
if (_storeWrapper != null) {
_storeWrapper.Close();
}
}
}
示例13: SetCertificate
public void SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue)
{
if (findValue == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
}
ThrowIfImmutable();
_certificate = SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
}
示例14: ConfigureAnonymousMessageSecurity
public void ConfigureAnonymousMessageSecurity(StoreLocation location,StoreName storeName,X509FindType findType,object findValue)
{
Credentials.ServiceCertificate.SetCertificate(location,storeName,findType,findValue);
Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
foreach(ServiceEndpoint endpoint in Description.Endpoints)
{
ServiceBusHelper.ConfigureBinding(endpoint.Binding);
}
}
示例15: SetCertificate
public void SetCertificate (StoreLocation storeLocation,
StoreName storeName, X509FindType findType,
object findValue)
{
#if !MOBILE
certificate = ConfigUtil.CreateCertificateFrom (storeLocation, storeName, findType, findValue);
#else
throw new NotImplementedException ();
#endif
}