本文整理汇总了C#中X509ContentType类的典型用法代码示例。如果您正苦于以下问题:C# X509ContentType类的具体用法?C# X509ContentType怎么用?C# X509ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509ContentType类属于命名空间,在下文中一共展示了X509ContentType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:9,代码来源:DirectoryBasedStoreProvider.cs
示例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();
}
}
开发者ID:rainersigwald,项目名称:corefx,代码行数:12,代码来源:CollectionBackedStoreProvider.cs
示例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);
}
}
开发者ID:AndreGleichner,项目名称:corefx,代码行数:17,代码来源:ExportProvider.cs
示例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);
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:80,代码来源:StorePal.Export.cs
示例5: Export
[System.Security.SecuritySafeCritical] // auto-generated
public virtual byte[] Export(X509ContentType contentType, SecureString password) {
return ExportHelper(contentType, password);
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:4,代码来源:x509certificate.cs
示例6: TestBlobContentType
public static void TestBlobContentType(byte[] blob, X509ContentType contentType)
{
X509ContentType blobType = X509Certificate2.GetCertContentType(blob);
Assert.Equal(contentType, blobType);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:5,代码来源:ContentTypeTests.cs
示例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;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:17,代码来源:x509certificate2collection.cs
示例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);
}
}
开发者ID:nbilling,项目名称:corefx,代码行数:13,代码来源:X509Certificate.cs
示例9: Export
public byte[] Export(X509ContentType contentType, String password)
{
using (IStorePal storePal = StorePal.LinkFromCertificateCollection(this))
{
return storePal.Export(contentType, password);
}
}
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:X509Certificate2Collection.cs
示例10: Export
public virtual byte[] Export(X509ContentType contentType);
开发者ID:ajit2936,项目名称:corefx-progress,代码行数:1,代码来源:System.Security.Cryptography.X509Certificates.cs
示例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);
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:11,代码来源:X509Certificate20.cs
示例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);
}
}
开发者ID:BrzVlad,项目名称:mono,代码行数:17,代码来源:X509CertificateImplBtls.cs
示例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;
}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:30,代码来源:X509CertificateExports.cs
示例14: Export
public static byte[] Export (X509CertificateImpl impl, X509ContentType contentType, byte[] password)
{
ThrowIfContextInvalid (impl);
return impl.Export (contentType, password);
}
开发者ID:Profit0004,项目名称:mono,代码行数:5,代码来源:X509Helper.cs
示例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;
}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:38,代码来源:X509CertificateExports.cs
示例16: TestFileContentType
public static void TestFileContentType(string fileName, X509ContentType contentType)
{
string fullPath = Path.Combine("TestData", fileName);
X509ContentType fileType = X509Certificate2.GetCertContentType(fullPath);
Assert.Equal(contentType, fileType);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:6,代码来源:ContentTypeTests.cs
示例17: _ExportCertificatesToBlob
internal static extern byte[] _ExportCertificatesToBlob(SafeCertStoreHandle safeCertStoreHandle, X509ContentType contentType, IntPtr password);
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:1,代码来源:x509utils.cs
示例18: TestExportSingleCert
private static void TestExportSingleCert(X509ContentType ct)
{
using (var msCer = new X509Certificate2(TestData.MsCertificate))
using (var pfxCer = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
{
X509Certificate2Collection cc = new X509Certificate2Collection(new X509Certificate2[] { msCer, pfxCer });
byte[] blob = cc.Export(ct);
Assert.Equal(ct, X509Certificate2.GetCertContentType(blob));
X509Certificate2Collection cc2 = new X509Certificate2Collection();
cc2.Import(blob);
int count = cc2.Count;
Assert.Equal(1, count);
using (X509Certificate2 c = cc2[0])
{
Assert.NotSame(msCer, c);
Assert.NotSame(pfxCer, c);
Assert.True(msCer.Equals(c) || pfxCer.Equals(c));
}
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:25,代码来源:CollectionTests.cs
示例19: TestExportStore
private static void TestExportStore(X509ContentType ct)
{
using (var msCer = new X509Certificate2(TestData.MsCertificate))
using (var pfxCer = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
{
X509Certificate2Collection cc = new X509Certificate2Collection(new X509Certificate2[] { msCer, pfxCer });
byte[] blob = cc.Export(ct);
Assert.Equal(ct, X509Certificate2.GetCertContentType(blob));
X509Certificate2Collection cc2 = new X509Certificate2Collection();
cc2.Import(blob);
int count = cc2.Count;
Assert.Equal(2, count);
X509Certificate2[] cs = cc2.ToArray().OrderBy(c => c.Subject).ToArray();
using (X509Certificate2 first = cs[0])
{
Assert.NotSame(msCer, first);
Assert.Equal(msCer, first);
}
using (X509Certificate2 second = cs[1])
{
Assert.NotSame(pfxCer, second);
Assert.Equal(pfxCer, second);
}
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:31,代码来源:CollectionTests.cs
示例20: ExportCertificatesToBlob
private unsafe static byte[] ExportCertificatesToBlob(Cryptography.SafeCertStoreHandle safeCertStoreHandle, X509ContentType contentType, string password) {
Cryptography.SafeCertContextHandle safeCertContextHandle = Cryptography.SafeCertContextHandle.InvalidHandle;
uint dwSaveAs = CAPI.CERT_STORE_SAVE_AS_PKCS7;
byte[] pbBlob = null;
CAPI.CRYPTOAPI_BLOB DataBlob = new CAPI.CRYPTOAPI_BLOB();
SafeLocalAllocHandle pbEncoded = SafeLocalAllocHandle.InvalidHandle;
switch(contentType) {
case X509ContentType.Cert:
safeCertContextHandle = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, safeCertContextHandle);
if (safeCertContextHandle != null && !safeCertContextHandle.IsInvalid) {
CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
pbBlob = new byte[pCertContext.cbCertEncoded];
Marshal.Copy(pCertContext.pbCertEncoded, pbBlob, 0, pbBlob.Length);
}
break;
case X509ContentType.SerializedCert:
safeCertContextHandle = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, safeCertContextHandle);
uint cbEncoded = 0;
if (safeCertContextHandle != null && !safeCertContextHandle.IsInvalid) {
if (!CAPI.CertSerializeCertificateStoreElement(safeCertContextHandle,
0,
pbEncoded,
new IntPtr(&cbEncoded)))
throw new CryptographicException(Marshal.GetLastWin32Error());
pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbEncoded));
if (!CAPI.CertSerializeCertificateStoreElement(safeCertContextHandle,
0,
pbEncoded,
new IntPtr(&cbEncoded)))
throw new CryptographicException(Marshal.GetLastWin32Error());
pbBlob = new byte[cbEncoded];
Marshal.Copy(pbEncoded.DangerousGetHandle(), pbBlob, 0, pbBlob.Length);
}
break;
case X509ContentType.Pkcs12:
if (!CAPI.PFXExportCertStore(safeCertStoreHandle,
new IntPtr(&DataBlob),
password,
CAPI.EXPORT_PRIVATE_KEYS | CAPI.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
throw new CryptographicException(Marshal.GetLastWin32Error());
pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(DataBlob.cbData));
DataBlob.pbData = pbEncoded.DangerousGetHandle();
if (!CAPI.PFXExportCertStore(safeCertStoreHandle,
new IntPtr(&DataBlob),
password,
CAPI.EXPORT_PRIVATE_KEYS | CAPI.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
throw new CryptographicException(Marshal.GetLastWin32Error());
pbBlob = new byte[DataBlob.cbData];
Marshal.Copy(DataBlob.pbData, pbBlob, 0, pbBlob.Length);
break;
case X509ContentType.SerializedStore:
// falling through
case X509ContentType.Pkcs7:
if (contentType == X509ContentType.SerializedStore)
dwSaveAs = CAPI.CERT_STORE_SAVE_AS_STORE;
// determine the required length
if (!CAPI.CertSaveStore(safeCertStoreHandle,
CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING,
dwSaveAs,
CAPI.CERT_STORE_SAVE_TO_MEMORY,
new IntPtr(&DataBlob),
0))
throw new CryptographicException(Marshal.GetLastWin32Error());
pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(DataBlob.cbData));
DataBlob.pbData = pbEncoded.DangerousGetHandle();
// now save the store to a memory blob
if (!CAPI.CertSaveStore(safeCertStoreHandle,
CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING,
dwSaveAs,
CAPI.CERT_STORE_SAVE_TO_MEMORY,
new IntPtr(&DataBlob),
0))
throw new CryptographicException(Marshal.GetLastWin32Error());
pbBlob = new byte[DataBlob.cbData];
Marshal.Copy(DataBlob.pbData, pbBlob, 0, pbBlob.Length);
break;
default:
throw new CryptographicException(SR.GetString(SR.Cryptography_X509_InvalidContentType));
}
pbEncoded.Dispose();
safeCertContextHandle.Dispose();
return pbBlob;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:96,代码来源:x509certificate2collection.cs
注:本文中的X509ContentType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论