本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2Collection.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2Collection.GetEnumerator方法的具体用法?C# X509Certificate2Collection.GetEnumerator怎么用?C# X509Certificate2Collection.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.X509Certificates.X509Certificate2Collection
的用法示例。
在下文中一共展示了X509Certificate2Collection.GetEnumerator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRange
public void AddRange(X509Certificate2Collection certificates)
{
if (certificates == null)
{
throw new ArgumentNullException("certificates");
}
int num = 0;
try
{
X509Certificate2Enumerator enumerator = certificates.GetEnumerator();
while (enumerator.MoveNext())
{
X509Certificate2 current = enumerator.Current;
this.Add(current);
num++;
}
}
catch
{
for (int i = 0; i < num; i++)
{
this.Remove(certificates[i]);
}
throw;
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:X509Certificate2Collection.cs
示例2: AddCertsToMessage
internal static unsafe uint AddCertsToMessage(System.Security.Cryptography.SafeCryptMsgHandle safeCryptMsgHandle, X509Certificate2Collection bagOfCerts, X509Certificate2Collection chainOfCerts)
{
uint num = 0;
X509Certificate2Enumerator enumerator = chainOfCerts.GetEnumerator();
while (enumerator.MoveNext())
{
X509Certificate2 current = enumerator.Current;
if (bagOfCerts.Find(X509FindType.FindByThumbprint, current.Thumbprint, false).Count == 0)
{
System.Security.Cryptography.CAPI.CERT_CONTEXT cert_context = *((System.Security.Cryptography.CAPI.CERT_CONTEXT*) System.Security.Cryptography.X509Certificates.X509Utils.GetCertContext(current).DangerousGetHandle());
System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB cryptoapi_blob = new System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB {
cbData = cert_context.cbCertEncoded,
pbData = cert_context.pbCertEncoded
};
if (!System.Security.Cryptography.CAPI.CryptMsgControl(safeCryptMsgHandle, 0, 10, new IntPtr((long) ((ulong) ((IntPtr) &cryptoapi_blob)))))
{
throw new CryptographicException(Marshal.GetLastWin32Error());
}
num++;
}
}
return num;
}
示例3: X509Certificate2Enumerator
internal X509Certificate2Enumerator(X509Certificate2Collection mappings)
{
this.baseEnumerator = mappings.GetEnumerator();
}
示例4: X509Certificate2Enumerator
internal X509Certificate2Enumerator(X509Certificate2Collection collection)
{
Debug.Assert(collection != null);
collection.GetEnumerator(out _enumerator);
}
示例5: CreateEncodedCertBlob
internal static unsafe System.Security.Cryptography.SafeLocalAllocHandle CreateEncodedCertBlob(X509Certificate2Collection certificates)
{
System.Security.Cryptography.SafeLocalAllocHandle invalidHandle = System.Security.Cryptography.SafeLocalAllocHandle.InvalidHandle;
if (certificates.Count > 0)
{
invalidHandle = System.Security.Cryptography.CAPI.LocalAlloc(0, new IntPtr(certificates.Count * Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB))));
System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB* handle = (System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB*) invalidHandle.DangerousGetHandle();
X509Certificate2Enumerator enumerator = certificates.GetEnumerator();
while (enumerator.MoveNext())
{
System.Security.Cryptography.CAPI.CERT_CONTEXT cert_context = *((System.Security.Cryptography.CAPI.CERT_CONTEXT*) System.Security.Cryptography.X509Certificates.X509Utils.GetCertContext(enumerator.Current).DangerousGetHandle());
handle->cbData = cert_context.cbCertEncoded;
handle->pbData = cert_context.pbCertEncoded;
handle++;
}
}
return invalidHandle;
}
示例6: GetPublicKey
//
// virtual methods
//
protected virtual AsymmetricAlgorithm GetPublicKey() {
if (KeyInfo == null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KeyInfoRequired"));
if (m_x509Enum != null) {
AsymmetricAlgorithm key = GetNextCertificatePublicKey();
if (key != null)
return key;
}
if (m_keyInfoEnum == null)
m_keyInfoEnum = KeyInfo.GetEnumerator();
// In our implementation, we move to the next KeyInfo clause which is an RSAKeyValue, DSAKeyValue or KeyInfoX509Data
while (m_keyInfoEnum.MoveNext()) {
RSAKeyValue rsaKeyValue = m_keyInfoEnum.Current as RSAKeyValue;
if (rsaKeyValue != null)
return rsaKeyValue.Key;
DSAKeyValue dsaKeyValue = m_keyInfoEnum.Current as DSAKeyValue;
if (dsaKeyValue != null)
return dsaKeyValue.Key;
KeyInfoX509Data x509Data = m_keyInfoEnum.Current as KeyInfoX509Data;
if (x509Data != null) {
m_x509Collection = Utils.BuildBagOfCerts (x509Data, CertUsageType.Verification);
if (m_x509Collection.Count > 0) {
m_x509Enum = m_x509Collection.GetEnumerator();
AsymmetricAlgorithm key = GetNextCertificatePublicKey();
if (key != null)
return key;
}
}
}
return null;
}
示例7: ExportToMemoryStore
private static System.IdentityModel.SafeCertStoreHandle ExportToMemoryStore(X509Certificate2Collection collection, IntPtr pCertContext)
{
System.IdentityModel.CAPI.CERT_CONTEXT cert_context = (System.IdentityModel.CAPI.CERT_CONTEXT) Marshal.PtrToStructure(pCertContext, typeof(System.IdentityModel.CAPI.CERT_CONTEXT));
if (((collection == null) || (collection.Count <= 0)) && (cert_context.hCertStore == IntPtr.Zero))
{
return System.IdentityModel.SafeCertStoreHandle.InvalidHandle;
}
System.IdentityModel.SafeCertStoreHandle hCertStore = System.IdentityModel.CAPI.CertOpenStore(new IntPtr(2L), 0x10001, IntPtr.Zero, 0x2200, null);
if ((hCertStore == null) || hCertStore.IsInvalid)
{
int hr = Marshal.GetLastWin32Error();
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(hr));
}
if ((collection != null) && (collection.Count > 0))
{
X509Certificate2Enumerator enumerator = collection.GetEnumerator();
while (enumerator.MoveNext())
{
X509Certificate2 current = enumerator.Current;
if (!System.IdentityModel.CAPI.CertAddCertificateLinkToStore(hCertStore, current.Handle, 4, System.IdentityModel.SafeCertContextHandle.InvalidHandle))
{
int num2 = Marshal.GetLastWin32Error();
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(num2));
}
}
}
if (cert_context.hCertStore != IntPtr.Zero)
{
X509Store store = new X509Store(cert_context.hCertStore);
X509Certificate2Collection certificates = null;
try
{
certificates = store.Certificates;
X509Certificate2Enumerator enumerator2 = certificates.GetEnumerator();
while (enumerator2.MoveNext())
{
X509Certificate2 certificate2 = enumerator2.Current;
if (!System.IdentityModel.CAPI.CertAddCertificateLinkToStore(hCertStore, certificate2.Handle, 4, System.IdentityModel.SafeCertContextHandle.InvalidHandle))
{
int num3 = Marshal.GetLastWin32Error();
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(num3));
}
}
}
finally
{
System.IdentityModel.SecurityUtils.ResetAllCertificates(certificates);
store.Close();
}
}
return hCertStore;
}