本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Extension类的典型用法代码示例。如果您正苦于以下问题:C# X509Extension类的具体用法?C# X509Extension怎么用?C# X509Extension使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509Extension类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了X509Extension类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public int Add(X509Extension extension)
{
if (extension == null)
throw new ArgumentNullException("extension");
_list.Add(extension);
return _list.Count - 1;
}
示例2: Add
public int Add(X509Extension extension)
{
if (extension == null)
{
throw new ArgumentNullException("extension");
}
return this.m_list.Add(extension);
}
示例3: CopyTo
public void CopyTo (X509Extension[] array, int index)
{
if (array == null)
throw new ArgumentNullException ("array");
if (index < 0)
throw new ArgumentException ("negative index");
if (index > array.Length)
throw new ArgumentOutOfRangeException ("index > array.Length");
}
示例4: ConstructorAsnEncodedData
public void ConstructorAsnEncodedData ()
{
AsnEncodedData aed = new AsnEncodedData (new Oid ("2.5.29.37"), new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 });
X509Extension ex = new X509Extension (aed, true);
Assert.IsTrue (ex.Critical, "Critical");
Assert.AreEqual (7, ex.RawData.Length, "RawData"); // original Oid ignored
Assert.AreEqual ("2.5.29.37", ex.Oid.Value, "Oid.Value");
Assert.AreEqual ("Enhanced Key Usage", ex.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, ex.Format (true), "Format(true)");
Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", ex.Format (false), "Format(false)");
}
示例5: MarshalX509Extension
public MarshalX509Extension(X509Extension extension)
{
_extension = extension;
_blobPtr = Marshal.AllocHGlobal(extension.RawData.Length);
Marshal.Copy(extension.RawData, 0, _blobPtr, extension.RawData.Length);
var blob = new CRYPT_OBJID_BLOB();
blob.cbData = (uint)extension.RawData.Length;
blob.pbData = _blobPtr;
var nativeExtension = new CERT_EXTENSION();
nativeExtension.fCritical = extension.Critical;
nativeExtension.pszObjId = extension.Oid.Value;
nativeExtension.Value = blob;
_value = nativeExtension;
}
示例6: SafeX509Extension
public SafeX509Extension(X509Extension extension)
{
this.blobPtr = Marshal.AllocHGlobal(extension.RawData.Length);
Marshal.Copy(extension.RawData, 0, this.blobPtr, extension.RawData.Length);
var blob = new CRYPTOAPI_BLOB
{
cbData = (uint)extension.RawData.Length,
pbData = this.blobPtr
};
var nativeExtension = new CERT_EXTENSION
{
fCritical = extension.Critical,
pszObjId = extension.Oid.Value,
Value = blob
};
this.value = nativeExtension;
}
示例7: X509ExtensionCollection
internal unsafe X509ExtensionCollection(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle)
{
this.m_list = new ArrayList();
using (System.Security.Cryptography.SafeCertContextHandle handle = CAPI.CertDuplicateCertificateContext(safeCertContextHandle))
{
CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) handle.DangerousGetHandle());
CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
uint cExtension = cert_info.cExtension;
IntPtr rgExtension = cert_info.rgExtension;
for (uint i = 0; i < cExtension; i++)
{
X509Extension asnEncodedData = new X509Extension(new IntPtr(((long) rgExtension) + (i * Marshal.SizeOf(typeof(CAPIBase.CERT_EXTENSION)))));
X509Extension extension2 = CryptoConfig.CreateFromName(asnEncodedData.Oid.Value) as X509Extension;
if (extension2 != null)
{
extension2.CopyFrom(asnEncodedData);
asnEncodedData = extension2;
}
this.Add(asnEncodedData);
}
}
}
示例8: ReadInhibitAnyPolicyExtension
private static int ReadInhibitAnyPolicyExtension(X509Extension extension)
{
DerSequenceReader reader = DerSequenceReader.CreateForPayload(extension.RawData);
return reader.ReadInteger();
}
示例9: ReadCertPolicyConstraintsExtension
private static void ReadCertPolicyConstraintsExtension(X509Extension extension, CertificatePolicy policy)
{
DerSequenceReader reader = new DerSequenceReader(extension.RawData);
while (reader.HasData)
{
// Policy Constraints context specific tag values are defined in RFC 3280 4.2.1.12,
// and restated (unchanged) in RFC 5280 4.2.1.11.
switch (reader.PeekTag())
{
case DerSequenceReader.ContextSpecificTagFlag | 0:
policy.RequireExplicitPolicyDepth = reader.ReadInteger();
break;
case DerSequenceReader.ContextSpecificTagFlag | 1:
policy.InhibitMappingDepth = reader.ReadInteger();
break;
default:
if (extension.Critical)
{
// If an unknown value is read, but we're marked as critical,
// then we don't know what we're doing and MUST fail validation
// (RFC 3280).
// If it isn't critical then it means we're allowed to be ignorant
// of data defined more recently than we understand.
throw new CryptographicException();
}
break;
}
}
}
示例10: WrongExtension_X509Extension
public void WrongExtension_X509Extension ()
{
X509Extension ex = new X509Extension ("1.2.3", new byte [0], true);
X509KeyUsageExtension ku = new X509KeyUsageExtension (X509KeyUsageFlags.CrlSign, true);
ku.CopyFrom (ex);
Assert.IsTrue (ku.Critical, "Critical");
Assert.AreEqual (String.Empty, BitConverter.ToString (ku.RawData), "RawData");
Assert.AreEqual ("1.2.3", ku.Oid.Value, "Oid.Value");
Assert.IsNull (ku.Oid.FriendlyName, "Oid.FriendlyName");
}
示例11: WrongExtension_X509Extension_KeyUsages
public void WrongExtension_X509Extension_KeyUsages ()
{
X509Extension ex = new X509Extension ("1.2.3", new byte[0], true);
X509KeyUsageExtension ku = new X509KeyUsageExtension ();
ku.CopyFrom (ex);
Assert.AreEqual (0, ku.KeyUsages, "KeyUsages");
}
示例12: WrongExtension_X509Extension
public void WrongExtension_X509Extension ()
{
X509Extension ex = new X509Extension ("1.2.3", new byte[0], true);
X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, true, 1, false);
Assert.IsFalse (bc.Critical, "Critical");
bc.CopyFrom (ex);
Assert.IsTrue (bc.Critical, "Critical");
Assert.AreEqual (String.Empty, BitConverter.ToString (bc.RawData), "RawData");
Assert.AreEqual ("1.2.3", bc.Oid.Value, "Oid.Value");
Assert.IsNull (bc.Oid.FriendlyName, "Oid.FriendlyName");
}
示例13: WrongExtension_X509Extension_CertificateAuthority
public void WrongExtension_X509Extension_CertificateAuthority ()
{
X509Extension ex = new X509Extension ("1.2.3", new byte[0], true);
X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension ();
bc.CopyFrom (ex);
bool b = bc.CertificateAuthority;
}
示例14: ReadCertPolicyMappingsExtension
private static List<CertificatePolicyMapping> ReadCertPolicyMappingsExtension(X509Extension extension)
{
DerSequenceReader reader = new DerSequenceReader(extension.RawData);
List<CertificatePolicyMapping> mappings = new List<CertificatePolicyMapping>();
while (reader.HasData)
{
DerSequenceReader mappingSequence = reader.ReadSequence();
mappings.Add(
new CertificatePolicyMapping
{
IssuerDomainPolicy = mappingSequence.ReadOidAsString(),
SubjectDomainPolicy = mappingSequence.ReadOidAsString(),
});
}
return mappings;
}
示例15: Build_NetscapeCertTypeExtension
public void Build_NetscapeCertTypeExtension ()
{
X509Extension ex = new X509Extension (new Oid ("2.16.840.1.113730.1.1"), new byte[] { 0x03, 0x02, 0x00, 0xFF }, false);
// strangely no NewLine is being appended to Format(true)
// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
//Assert.AreEqual ("SSL Client Authentication, SSL Server Authentication, SMIME, Signature, Unknown cert type, SSL CA, SMIME CA, Signature CA (ff)", ex.Format (true), "aed.Format(true)");
//Assert.AreEqual ("SSL Client Authentication, SSL Server Authentication, SMIME, Signature, Unknown cert type, SSL CA, SMIME CA, Signature CA (ff)", ex.Format (false), "aed.Format(false)");
}