本文整理汇总了C#中X509Certificate类的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate类的具体用法?C# X509Certificate怎么用?C# X509Certificate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509Certificate类属于命名空间,在下文中一共展示了X509Certificate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ServerContext
public ServerContext(
SslServerStream stream,
SecurityProtocolType securityProtocolType,
X509Certificate serverCertificate,
bool clientCertificateRequired)
: base(securityProtocolType)
{
this.sslStream = stream;
this.clientCertificateRequired = clientCertificateRequired;
// Convert the System.Security cert to a Mono Cert
MonoX509.X509Certificate cert = new MonoX509.X509Certificate(serverCertificate.GetRawCertData());
// Add server certificate to the certificate collection
this.ServerSettings.Certificates = new MonoX509.X509CertificateCollection();
this.ServerSettings.Certificates.Add(cert);
this.ServerSettings.UpdateCertificateRSA();
// Add requested certificate types
this.ServerSettings.CertificateTypes = new ClientCertificateType[1];
this.ServerSettings.CertificateTypes[0] = ClientCertificateType.RSA;
// Add certificate authorities
this.ServerSettings.DistinguisedNames = new string[0];
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:26,代码来源:ServerContext.cs
示例2: TcpTransport
public TcpTransport(string host,int port, X509Certificate clientCertificate, bool loggingEnabled = false)
{
EPP_REGISTRY_COM = host;
PORT = port;
this.loggingEnabled = loggingEnabled;
this.clientCertificate = clientCertificate;
}
开发者ID:softwareengr,项目名称:EppLib.NET,代码行数:7,代码来源:TcpTransport.cs
示例3: X509Certificate2CollectionConstructors
public static void X509Certificate2CollectionConstructors()
{
using (X509Certificate2 c1 = new X509Certificate2())
using (X509Certificate2 c2 = new X509Certificate2())
using (X509Certificate2 c3 = new X509Certificate2())
{
X509Certificate2Collection cc = new X509Certificate2Collection(new X509Certificate2[] { c1, c2, c3 });
Assert.Equal(3, cc.Count);
Assert.Same(c1, cc[0]);
Assert.Same(c2, cc[1]);
Assert.Same(c3, cc[2]);
X509Certificate2Collection cc2 = new X509Certificate2Collection(cc);
Assert.Equal(3, cc2.Count);
Assert.Same(c1, cc2[0]);
Assert.Same(c2, cc2[1]);
Assert.Same(c3, cc2[2]);
Assert.Throws<ArgumentNullException>(() => new X509Certificate2Collection(new X509Certificate2[] { c1, c2, null, c3 }));
using (X509Certificate c4 = new X509Certificate())
{
X509Certificate2Collection collection = new X509Certificate2Collection { c1, c2, c3 };
((IList)collection).Add(c4); // Add non-X509Certificate2 object
Assert.Throws<InvalidCastException>(() => new X509Certificate2Collection(collection));
}
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:29,代码来源:CollectionTests.cs
示例4: SslServer
// Initialize all of the default certificates and protocols
public SslServer()
{
// Initialize the Socket
serverSocketType = SocketType.Stream;
serverProtocolType = ProtocolType.Tcp;
if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
{
cert = new X509Certificate(CertificatesAndCAs.emuCert, "NetMF");
ca = new X509Certificate[] { new X509Certificate(CertificatesAndCAs.caEmuCert) };
}
else
{
// Initialize the SslStream
cert = new X509Certificate(CertificatesAndCAs.newCert);
ca = new X509Certificate[] { new X509Certificate(CertificatesAndCAs.caCert) };
}
verify = SslVerification.NoVerification;
sslProtocols = new SslProtocols[] { SslProtocols.Default };
// Create a TCP/IP (IPv4) socket and listen for incoming connections.
serverSocket = new Socket(AddressFamily.InterNetwork, serverSocketType, serverProtocolType);
serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, false);
serverSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
serverEp = (IPEndPoint)serverSocket.LocalEndPoint;
Debug.Print("Listening for a client to connect...");
serverSocket.Listen(1);
}
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:31,代码来源:SslServer.cs
示例5: TestImportNotSupported_X509Certificate
public static void TestImportNotSupported_X509Certificate()
{
using (var c = new X509Certificate())
{
VerifyImportNotSupported(c);
}
}
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:ImportTests.cs
示例6: IsSignedBy
public virtual bool IsSignedBy(X509Certificate potentialIssuer)
{
try
{
x509crl.Verify(potentialIssuer.GetPublicKey());
return true;
}
catch (InvalidKeyException)
{
return false;
}
/*catch (CrlException)
{
return false;
}*/
catch (NoSuchAlgorithmException)
{
return false;
}
/*catch (NoSuchProviderException e)
{
throw new RuntimeException(e);
}*/
catch (SignatureException)
{
return false;
}
}
开发者ID:Gianluigi,项目名称:dssnet,代码行数:28,代码来源:CRLToken.cs
示例7: CanCreateAndDispose
public void CanCreateAndDispose()
{
using (var cert = new X509Certificate())
{
cert.PrintRefCount();
}
}
开发者ID:yaobos,项目名称:openssl-net,代码行数:7,代码来源:TestX509Certificate.cs
示例8: ValidateServerCertificate
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
{
return true;
}
byte[] receivedCertificateHash = certificate.GetCertHash();
//If length differs, obviously different hash.
if (receivedCertificateHash.Length != hardCodedServerCertificateHash.Length)
{
return false;
}
//Check that each byte is the same
for (int i = 0; i < hardCodedServerCertificateHash.Length; i++)
{
if (receivedCertificateHash[i] != hardCodedServerCertificateHash[i])
{
return false;
}
}
//Equality of the certificates confirmed.
return true;
}
开发者ID:Tsarpf,项目名称:Mobile-MMO,代码行数:26,代码来源:SynchronousNetworkLoop.cs
示例9: CanAddExtensions
public void CanAddExtensions()
{
X509V3ExtensionList extList = new X509V3ExtensionList();
extList.Add(new X509V3ExtensionValue("subjectKeyIdentifier", false, "hash"));
extList.Add(new X509V3ExtensionValue("authorityKeyIdentifier", false, "keyid:always,issuer:always"));
extList.Add(new X509V3ExtensionValue("basicConstraints", true, "critical,CA:true"));
extList.Add(new X509V3ExtensionValue("keyUsage", false, "cRLSign,keyCertSign"));
DateTime start = DateTime.Now;
DateTime end = start + TimeSpan.FromMinutes(10);
CryptoKey key = new CryptoKey(new DSA(true));
using (X509Certificate cert = new X509Certificate(101, "CN=Root", "CN=Root", key, start, end)) {
foreach (X509V3ExtensionValue extValue in extList) {
using (X509Extension ext = new X509Extension(cert, cert, extValue.Name, extValue.IsCritical, extValue.Value)) {
cert.AddExtension(ext);
}
}
foreach (X509Extension ext in cert.Extensions) {
Console.WriteLine(ext);
}
Assert.AreEqual(extList.Count, cert.Extensions.Count);
}
}
开发者ID:LiorNaor,项目名称:openssl-net,代码行数:25,代码来源:TestX509Certificate.cs
示例10: ServerContext
public ServerContext(
SslServerStream stream,
SecurityProtocolType securityProtocolType,
X509Certificate serverCertificate,
bool clientCertificateRequired)
: base(securityProtocolType)
{
this.sslStream = stream;
this.clientCertificateRequired = clientCertificateRequired;
// Convert the System.Security cert to a Mono Cert
MonoX509.X509Certificate cert = new MonoX509.X509Certificate(serverCertificate.GetRawCertData());
// Add server certificate to the certificate collection
this.ServerSettings.Certificates = new MonoX509.X509CertificateCollection();
this.ServerSettings.Certificates.Add(cert);
this.ServerSettings.UpdateCertificateRSA();
// Add requested certificate types
this.ServerSettings.CertificateTypes = new ClientCertificateType[1];
this.ServerSettings.CertificateTypes[0] = ClientCertificateType.RSA;
// Add certificate authorities
MonoX509.X509CertificateCollection trusted = MonoX509.X509StoreManager.TrustedRootCertificates;
string[] list = new string [trusted.Count];
int i = 0;
foreach (MonoX509.X509Certificate root in trusted)
{
list [i++] = root.IssuerName;
}
this.ServerSettings.DistinguisedNames = list;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:33,代码来源:ServerContext.cs
示例11: SslStreamServer
public SslStreamServer(
Stream stream,
bool ownStream,
X509Certificate serverCertificate,
bool clientCertificateRequired,
X509Chain caCerts,
SslProtocols enabledSslProtocols,
SslStrength sslStrength,
bool checkCertificateRevocation,
RemoteCertificateValidationHandler remote_callback)
: base(stream, ownStream)
{
this.checkCertificateRevocationStatus = checkCertificateRevocation;
this.remoteCertificateSelectionCallback = remote_callback;
// Initialize the SslContext object
InitializeServerContext(serverCertificate, clientCertificateRequired, caCerts, enabledSslProtocols, sslStrength, checkCertificateRevocation);
ssl = new Ssl(sslContext);
// Initialze the read/write bio
read_bio = BIO.MemoryBuffer(false);
write_bio = BIO.MemoryBuffer(false);
// Set the read/write bio's into the the Ssl object
ssl.SetBIO(read_bio, write_bio);
read_bio.SetClose(BIO.CloseOption.Close);
write_bio.SetClose(BIO.CloseOption.Close);
// Set the Ssl object into server mode
ssl.SetAcceptState();
}
开发者ID:loonbg,项目名称:mooege,代码行数:29,代码来源:SslStreamServer.cs
示例12: GetSubjectAlternativeNames
public static ICollection GetSubjectAlternativeNames(
X509Certificate cert)
{
Asn1OctetString extVal = cert.GetExtensionValue(X509Extensions.SubjectAlternativeName);
return GetAlternativeName(extVal);
}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:7,代码来源:X509ExtensionUtil.cs
示例13: FromCertificate
private static Asn1Sequence FromCertificate(
X509Certificate certificate)
{
try
{
GeneralName genName = new GeneralName(
PrincipalUtilities.GetIssuerX509Principal(certificate));
if (certificate.Version == 3)
{
Asn1OctetString ext = certificate.GetExtensionValue(X509Extensions.SubjectKeyIdentifier);
if (ext != null)
{
Asn1OctetString str = (Asn1OctetString) X509ExtensionUtilities.FromExtensionValue(ext);
return (Asn1Sequence) new AuthorityKeyIdentifier(
str.GetOctets(), new GeneralNames(genName), certificate.SerialNumber).ToAsn1Object();
}
}
SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(
certificate.GetPublicKey());
return (Asn1Sequence) new AuthorityKeyIdentifier(
info, new GeneralNames(genName), certificate.SerialNumber).ToAsn1Object();
}
catch (Exception e)
{
throw new CertificateParsingException("Exception extracting certificate details", e);
}
}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:32,代码来源:AuthorityKeyIdentifierStructure.cs
示例14: Validator
// The GitHub SSL certificate is corrupt, or something? Who cares.
public static bool Validator(
object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors
)
{
return true;
}
开发者ID:adunndevster,项目名称:jaxi,代码行数:8,代码来源:oauth_get_token.aspx.cs
示例15: PosTest1
public bool PosTest1()
{
bool retVal = true;
X509Certificate cer;
TestLibrary.TestFramework.BeginScenario("PosTest1: Valid certificate");
try
{
cer = new X509Certificate(c_VALIDPATH);
if (null == cer)
{
TestLibrary.TestFramework.LogError("-01", "Failed to load " + c_VALIDPATH);
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("000", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:25,代码来源:X509CertificateLoadCertFromFile.cs
示例16: CanLoadFromPEM
public void CanLoadFromPEM()
{
using (BIO bio = new BIO(LoadString(Resources.CaCrt))) {
using (X509Certificate cert = new X509Certificate(bio)) {
TestCert(cert, "CN=Root", "CN=Root", 1234);
}
}
}
开发者ID:challal,项目名称:scallion,代码行数:8,代码来源:TestX509Certificate.cs
示例17: X509Extension
/// <summary>
/// Calls X509V3_EXT_conf_nid()
/// </summary>
/// <param name="issuer"></param>
/// <param name="subject"></param>
/// <param name="name"></param>
/// <param name="critical"></param>
/// <param name="value"></param>
public X509Extension(X509Certificate issuer, X509Certificate subject, string name, bool critical, string value)
: base(IntPtr.Zero, true)
{
using (var ctx = new X509V3Context(issuer, subject, null))
{
ptr = Native.ExpectNonNull(Native.X509V3_EXT_conf_nid(IntPtr.Zero, ctx.Handle, Native.TextToNID(name), value));
}
}
开发者ID:ebekker,项目名称:openssl-net,代码行数:16,代码来源:X509Extension.cs
示例18: NegTest3
public bool NegTest3(string fileName) { return NegTest(3, "Import(byte[])", fileName,
delegate(string fName)
{
X509Certificate cer;
cer = new X509Certificate();
cer.Import(BytesFromFile(fName));
return false;
} ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs
示例19: NegTest2
public bool NegTest2(string fileName) { return NegTest(2, "Import(String,String,X509KeyStorageFlags)", fileName,
delegate(string fName)
{
X509Certificate cer;
cer = new X509Certificate();
cer.Import(fName, "", X509KeyStorageFlags.DefaultKeySet);
return false;
} ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs
示例20: NegTest1
public bool NegTest1(string fileName) { return NegTest(1, "Import(String)", fileName,
delegate(string fName)
{
X509Certificate cer;
cer = new X509Certificate();
cer.Import(fName);
return false;
} ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs
注:本文中的X509Certificate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论