本文整理汇总了C#中X509ContentType类的典型用法代码示例。如果您正苦于以下问题:C# X509ContentType类的具体用法?C# X509ContentType怎么用?C# X509ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509ContentType类属于命名空间,在下文中一共展示了X509ContentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Export
public byte[] Export(X509ContentType contentType, string password)
{
// Export is for X509Certificate2Collections in their IStorePal guise,
// if someone wanted to export whole stores they'd need to do
// store.Certificates.Export(...), which would end up in the
// CollectionBackedStoreProvider.
Debug.Fail("Export was unexpected on a DirectoryBasedStore");
throw new InvalidOperationException();
}
示例2: Export
public byte[] Export(X509ContentType contentType, string password)
{
switch (contentType)
{
case X509ContentType.Cert:
return ExportX509Der();
case X509ContentType.Pfx:
return ExportPfx(password);
default:
throw new NotImplementedException();
}
}
示例3: Export
public byte[] Export(X509ContentType contentType, string password)
{
switch (contentType)
{
case X509ContentType.Cert:
return ExportX509Der();
case X509ContentType.Pfx:
return ExportPfx(password);
case X509ContentType.Pkcs7:
return ExportPkcs7();
case X509ContentType.SerializedCert:
case X509ContentType.SerializedStore:
throw new PlatformNotSupportedException(SR.Cryptography_Unix_X509_SerializedExport);
default:
throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
}
}
示例4: Export
public byte[] Export(X509ContentType contentType, string password)
{
switch (contentType)
{
case X509ContentType.Cert:
{
SafeCertContextHandle pCertContext = null;
if (!Interop.crypt32.CertEnumCertificatesInStore(_certStore, ref pCertContext))
return null;
try
{
unsafe
{
byte[] rawData = new byte[pCertContext.CertContext->cbCertEncoded];
Marshal.Copy((IntPtr)(pCertContext.CertContext->pbCertEncoded), rawData, 0, rawData.Length);
GC.KeepAlive(pCertContext);
return rawData;
}
}
finally
{
pCertContext.Dispose();
}
}
case X509ContentType.SerializedCert:
{
SafeCertContextHandle pCertContext = null;
if (!Interop.crypt32.CertEnumCertificatesInStore(_certStore, ref pCertContext))
return null;
try
{
int cbEncoded = 0;
if (!Interop.crypt32.CertSerializeCertificateStoreElement(pCertContext, 0, null, ref cbEncoded))
throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
byte[] pbEncoded = new byte[cbEncoded];
if (!Interop.crypt32.CertSerializeCertificateStoreElement(pCertContext, 0, pbEncoded, ref cbEncoded))
throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
return pbEncoded;
}
finally
{
pCertContext.Dispose();
}
}
case X509ContentType.Pkcs12:
{
unsafe
{
CRYPTOAPI_BLOB dataBlob = new CRYPTOAPI_BLOB(0, (byte*)null);
if (!Interop.crypt32.PFXExportCertStore(_certStore, ref dataBlob, password, PFXExportFlags.EXPORT_PRIVATE_KEYS | PFXExportFlags.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
byte[] pbEncoded = new byte[dataBlob.cbData];
fixed (byte* ppbEncoded = pbEncoded)
{
dataBlob.pbData = ppbEncoded;
if (!Interop.crypt32.PFXExportCertStore(_certStore, ref dataBlob, password, PFXExportFlags.EXPORT_PRIVATE_KEYS | PFXExportFlags.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
}
return pbEncoded;
}
}
case X509ContentType.SerializedStore:
return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_STORE);
case X509ContentType.Pkcs7:
return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_PKCS7);
default:
throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
}
}
示例5: Export
[System.Security.SecuritySafeCritical] // auto-generated
public virtual byte[] Export(X509ContentType contentType, SecureString password) {
return ExportHelper(contentType, password);
}
示例6: TestBlobContentType
public static void TestBlobContentType(byte[] blob, X509ContentType contentType)
{
X509ContentType blobType = X509Certificate2.GetCertContentType(blob);
Assert.Equal(contentType, blobType);
}
示例7: Export
public byte[] Export(X509ContentType contentType, string password) {
#if !FEATURE_CORESYSTEM
//
// We need to Assert all StorePermission flags since this is a memory store and we want
// semi-trusted code to be able to export certificates to a memory store.
//
StorePermission sp = new StorePermission(StorePermissionFlags.AllFlags);
sp.Assert();
#endif
Cryptography.SafeCertStoreHandle safeCertStoreHandle = X509Utils.ExportToMemoryStore(this);
byte[] result = ExportCertificatesToBlob(safeCertStoreHandle, contentType, password);
safeCertStoreHandle.Dispose();
return result;
}
示例8: Export
public virtual byte[] Export(X509ContentType contentType, string password)
{
if (!(contentType == X509ContentType.Cert || contentType == X509ContentType.SerializedCert || contentType == X509ContentType.Pkcs12))
throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
if (Pal == null)
throw new CryptographicException(ErrorCode.E_POINTER); // Not the greatest error, but needed for backward compat.
using (IStorePal storePal = StorePal.FromCertificate(Pal))
{
return storePal.Export(contentType, password);
}
}
示例9: Export
public byte[] Export(X509ContentType contentType, String password)
{
using (IStorePal storePal = StorePal.LinkFromCertificateCollection(this))
{
return storePal.Export(contentType, password);
}
}
示例10: Export
public virtual byte[] Export(X509ContentType contentType);
示例11: Export
internal byte[] Export (X509ContentType contentType, byte[] password)
{
try {
X509Helper.ThrowIfContextInvalid (impl);
return impl.Export (contentType, password);
} finally {
// protect password
if (password != null)
Array.Clear (password, 0, password.Length);
}
}
示例12: Export
public override byte[] Export (X509ContentType contentType, string password)
{
ThrowIfContextInvalid ();
switch (contentType) {
case X509ContentType.Cert:
return GetRawCertData ();
case X509ContentType.Pfx: // this includes Pkcs12
return ExportPkcs12 (password);
case X509ContentType.SerializedCert:
// TODO
throw new NotSupportedException ();
default:
string msg = Locale.GetText ("This certificate format '{0}' cannot be exported.", contentType);
throw new CryptographicException (msg);
}
}
示例13: PosTest
public bool PosTest(int id, string msg, X509ContentType x509ConType, TestDelegate d)
{
bool retVal = true;
X509Certificate cer;
byte[] bytes;
TestLibrary.TestFramework.BeginScenario("PosTest"+id+": " + msg + " = " + x509ConType);
try
{
cer = new X509Certificate(c_CERTFILE);
bytes = d(cer, x509ConType);
if (null == bytes)
{
TestLibrary.TestFramework.LogError("000", "Export return null!");
TestLibrary.TestFramework.LogInformation("");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation("");
retVal = false;
}
return retVal;
}
示例14: Export
public static byte[] Export (X509CertificateImpl impl, X509ContentType contentType, byte[] password)
{
ThrowIfContextInvalid (impl);
return impl.Export (contentType, password);
}
示例15: NegTest
public bool NegTest(int id, string msg, X509ContentType x509ConType, TestDelegate d)
{
bool retVal = true;
X509Certificate cer;
byte[] bytes;
TestLibrary.TestFramework.BeginScenario("NegTest"+id+": "+msg+" = " + x509ConType);
try
{
cer = new X509Certificate(c_CERTFILE);
bytes = d(cer, x509ConType);
TestLibrary.TestFramework.LogError("002", "Exception should have been thrown.");
TestLibrary.TestFramework.LogInformation("");
retVal = false;
}
catch (CryptographicException e)
{
// expected
// ensure that the message does NOT contain "Unknown error"
if (e.Message.ToLower().Contains("unknown error"))
{
TestLibrary.TestFramework.LogError("003", "Unexpected exception message (should not be unkown): " + e);
TestLibrary.TestFramework.LogInformation("");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation("");
retVal = false;
}
return retVal;
}