本文整理汇总了C#中System.Security.Cryptography.OidCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# OidCollection.Add方法的具体用法?C# OidCollection.Add怎么用?C# OidCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.OidCollection
的用法示例。
在下文中一共展示了OidCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnumerator
private OidEnumerator GetEnumerator ()
{
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.0"));
oc.Add (new Oid ("1.1"));
oc.Add (new Oid ("1.2"));
return oc.GetEnumerator ();
}
示例2: CopyToOidNull
public void CopyToOidNull ()
{
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.0"));
Oid[] array = null;
oc.CopyTo (array, 0);
}
示例3: AddNull
//BUG [ExpectedException (typeof (ArgumentNullException))]
public void AddNull ()
{
OidCollection oc = new OidCollection ();
oc.Add (null);
Assert.AreEqual (1, oc.Count, "Count");
// Assert.IsNull (oc, "[0]"); throw NullReferenceException
}
示例4: AddNull
//BUG [ExpectedException (typeof (ArgumentNullException))]
public void AddNull ()
{
OidCollection oc = new OidCollection ();
oc.Add (null);
AssertEquals ("Count", 1, oc.Count);
// AssertNull ("[0]", oc); throw NullReferenceException
}
示例5: CopyToOid
public void CopyToOid ()
{
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.0"));
Oid[] array = new Oid [1];
oc.CopyTo (array, 0);
Assert.AreEqual ("1.0", array [0].Value, "CopyTo(Oid)");
}
示例6: Add
public void Add ()
{
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.0"));
Assert.AreEqual (1, oc.Count, "Count");
Assert.AreEqual ("1.0", oc [0].Value, "[0]");
Assert.AreEqual ("1.0", oc ["1.0"].Value, "['1.0']");
}
示例7: Add
public void Add ()
{
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.0"));
AssertEquals ("Count", 1, oc.Count);
AssertEquals ("[0]", "1.0", oc [0].Value);
AssertEquals ("['1.0']", "1.0", oc ["1.0"].Value);
}
示例8: CreateSelfSignedCert
/// <summary>
/// Creates a new self-signed X509 certificate
/// </summary>
/// <param name="issuer">The certificate issuer</param>
/// <param name="friendlyName">Human readable name</param>
/// <param name="password">The certificate's password</param>
/// <param name="startTime">Certificate creation date & time</param>
/// <param name="endTime">Certificate expiry date & time</param>
/// <returns>An X509Certificate2</returns>
public static X509Certificate2 CreateSelfSignedCert(string issuer, string friendlyName, string password, DateTime startTime, DateTime endTime)
{
string distinguishedNameString = issuer;
var key = Create2048RsaKey();
var creationParams = new X509CertificateCreationParameters(new X500DistinguishedName(distinguishedNameString))
{
TakeOwnershipOfKey = true,
StartTime = startTime,
EndTime = endTime
};
// adding client authentication, -eku = 1.3.6.1.5.5.7.3.2,
// This is mandatory for the upload to be successful
OidCollection oidCollection = new OidCollection();
oidCollection.Add(new Oid(OIDClientAuthValue, OIDClientAuthFriendlyName));
creationParams.Extensions.Add(new X509EnhancedKeyUsageExtension(oidCollection, false));
// Documentation of CreateSelfSignedCertificate states:
// If creationParameters have TakeOwnershipOfKey set to true, the certificate
// generated will own the key and the input CngKey will be disposed to ensure
// that the caller doesn't accidentally use it beyond its lifetime (which is
// now controlled by the certificate object).
// We don't dispose it ourselves in this case.
var cert = key.CreateSelfSignedCertificate(creationParams);
key = null;
cert.FriendlyName = friendlyName;
// X509 certificate needs PersistKeySet flag set.
// Reload a new X509Certificate2 instance from exported bytes in order to set the PersistKeySet flag.
var bytes = cert.Export(X509ContentType.Pfx, password);
// NOTE: PfxValidation is not done here because these are newly created certs and assumed valid.
ICommonEventSource evtSource = null;
return X509Certificate2Helper.NewX509Certificate2(bytes, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable, evtSource, doPfxValidation: false);
}
示例9: DecodeX509EnhancedKeyUsageExtension
public void DecodeX509EnhancedKeyUsageExtension(byte[] encoded, out OidCollection usages)
{
OidCollection localUsages = new OidCollection();
unsafe
{
encoded.DecodeObject(
CryptDecodeObjectStructType.X509_ENHANCED_KEY_USAGE,
delegate (void* pvDecoded)
{
CERT_ENHKEY_USAGE* pEnhKeyUsage = (CERT_ENHKEY_USAGE*)pvDecoded;
int count = pEnhKeyUsage->cUsageIdentifier;
for (int i = 0; i < count; i++)
{
IntPtr oidValuePointer = pEnhKeyUsage->rgpszUsageIdentifier[i];
string oidValue = Marshal.PtrToStringAnsi(oidValuePointer);
Oid oid = new Oid(oidValue);
localUsages.Add(oid);
}
}
);
}
usages = localUsages;
}
示例10: DecodeExtension
private void DecodeExtension () {
uint cbDecoded = 0;
SafeLocalAllocHandle decoded = null;
bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_ENHANCED_KEY_USAGE),
m_rawData,
out decoded,
out cbDecoded);
if (result == false)
throw new CryptographicException(Marshal.GetLastWin32Error());
CAPI.CERT_ENHKEY_USAGE pEnhKeyUsage = (CAPI.CERT_ENHKEY_USAGE) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CERT_ENHKEY_USAGE));
m_enhancedKeyUsages = new OidCollection();
for (int index = 0; index < pEnhKeyUsage.cUsageIdentifier; index++) {
IntPtr pszOid = Marshal.ReadIntPtr(new IntPtr((long) pEnhKeyUsage.rgpszUsageIdentifier + index * Marshal.SizeOf(typeof(IntPtr))));
string oidValue = Marshal.PtrToStringAnsi(pszOid);
Oid oid = new Oid(oidValue, OidGroup.ExtensionOrAttribute, false);
m_enhancedKeyUsages.Add(oid);
}
m_decoded = true;
decoded.Dispose();
}
示例11: DecodeX509EnhancedKeyUsageExtension
public void DecodeX509EnhancedKeyUsageExtension(byte[] encoded, out OidCollection usages)
{
OidCollection oids = new OidCollection();
using (SafeEkuExtensionHandle eku = Interop.Crypto.DecodeExtendedKeyUsage(encoded, encoded.Length))
{
Interop.Crypto.CheckValidOpenSslHandle(eku);
int count = Interop.Crypto.GetX509EkuFieldCount(eku);
for (int i = 0; i < count; i++)
{
IntPtr oidPtr = Interop.Crypto.GetX509EkuField(eku, i);
if (oidPtr == IntPtr.Zero)
{
throw Interop.Crypto.CreateOpenSslCryptographicException();
}
string oidValue = Interop.Crypto.GetOidValue(oidPtr);
oids.Add(new Oid(oidValue));
}
}
usages = oids;
}
示例12: DecodeX509EnhancedKeyUsageExtension
public unsafe void DecodeX509EnhancedKeyUsageExtension(byte[] encoded, out OidCollection usages)
{
OidCollection oids = new OidCollection();
using (SafeEkuExtensionHandle eku = Interop.libcrypto.OpenSslD2I(Interop.libcrypto.d2i_EXTENDED_KEY_USAGE, encoded))
{
Interop.libcrypto.CheckValidOpenSslHandle(eku);
int count = Interop.Crypto.GetX509EkuFieldCount(eku);
for (int i = 0; i < count; i++)
{
IntPtr oidPtr = Interop.Crypto.GetX509EkuField(eku, i);
if (oidPtr == IntPtr.Zero)
{
throw Interop.libcrypto.CreateOpenSslCryptographicException();
}
string oidValue = Interop.libcrypto.OBJ_obj2txt_helper(oidPtr);
oids.Add(new Oid(oidValue));
}
}
usages = oids;
}
示例13: ReadOnlyCopy
internal OidCollection ReadOnlyCopy ()
{
OidCollection copy = new OidCollection ();
foreach (Oid oid in _list) {
copy.Add (oid);
}
copy._readOnly = true;
return copy;
}
示例14: CopyFrom_Self
public void CopyFrom_Self ()
{
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.2.3.4"));
X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (oc, true);
Assert.IsTrue (eku.Critical, "Critical");
byte[] raw = eku.RawData;
Assert.AreEqual ("30-05-06-03-2A-03-04", BitConverter.ToString (raw), "RawData");
AsnEncodedData aed = new AsnEncodedData (raw);
X509EnhancedKeyUsageExtension copy = new X509EnhancedKeyUsageExtension (aed, false);
Assert.IsFalse (copy.Critical, "Critical");
Assert.AreEqual (7, copy.RawData.Length, "RawData"); // original Oid ignored
Assert.AreEqual (oid, copy.Oid.Value, "Oid.Value");
// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
//Assert.AreEqual (fname, copy.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (1, copy.EnhancedKeyUsages.Count, "EnhancedKeyUsages");
Assert.AreEqual ("1.2.3.4", copy.EnhancedKeyUsages[0].Value, "EnhancedKeyUsages Oid");
}
示例15: WrongExtension_X509Extension
public void WrongExtension_X509Extension ()
{
X509Extension ex = new X509Extension ("1.2.3", new byte[0], true);
OidCollection oc = new OidCollection ();
oc.Add (new Oid ("1.2.3.4"));
X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (oc, false);
Assert.AreEqual (1, eku.EnhancedKeyUsages.Count, "EnhancedKeyUsages");
Assert.IsFalse (eku.Critical, "Critical");
eku.CopyFrom (ex);
Assert.IsTrue (eku.Critical, "Critical");
Assert.AreEqual (String.Empty, BitConverter.ToString (eku.RawData), "RawData");
Assert.AreEqual ("1.2.3", eku.Oid.Value, "Oid.Value");
Assert.IsNull (eku.Oid.FriendlyName, "Oid.FriendlyName");
}