本文整理汇总了C#中ICertificatePal类的典型用法代码示例。如果您正苦于以下问题:C# ICertificatePal类的具体用法?C# ICertificatePal怎么用?C# ICertificatePal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICertificatePal类属于命名空间,在下文中一共展示了ICertificatePal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DecodePublicKey
public AsymmetricAlgorithm DecodePublicKey(Oid oid, byte[] encodedKeyValue, byte[] encodedParameters, ICertificatePal certificatePal)
{
if (oid.Value == Oids.Ecc)
{
return DecodeECDsaPublicKey((CertificatePal)certificatePal);
}
int algId = OidInfo.FindOidInfo(CryptOidInfoKeyType.CRYPT_OID_INFO_OID_KEY, oid.Value, OidGroup.PublicKeyAlgorithm, fallBackToAllGroups: true).AlgId;
switch (algId)
{
case AlgId.CALG_RSA_KEYX:
case AlgId.CALG_RSA_SIGN:
{
byte[] keyBlob = DecodeKeyBlob(CryptDecodeObjectStructType.CNG_RSA_PUBLIC_KEY_BLOB, encodedKeyValue);
CngKey cngKey = CngKey.Import(keyBlob, CngKeyBlobFormat.GenericPublicBlob);
return new RSACng(cngKey);
}
#if !NETNATIVE
case AlgId.CALG_DSS_SIGN:
{
byte[] keyBlob = ConstructDSSPublicKeyCspBlob(encodedKeyValue, encodedParameters);
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
dsa.ImportCspBlob(keyBlob);
return dsa;
}
#endif
default:
throw new NotSupportedException(SR.NotSupported_KeyAlgorithm);
}
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:32,代码来源:X509Pal.PublicKey.cs
示例2: BuildChain
public static IChainPal BuildChain(
bool useMachineContext,
ICertificatePal cert,
X509Certificate2Collection extraStore,
OidCollection applicationPolicy,
OidCollection certificatePolicy,
X509RevocationMode revocationMode,
X509RevocationFlag revocationFlag,
DateTime verificationTime,
TimeSpan timeout)
{
// An input value of 0 on the timeout is "take all the time you need".
if (timeout == TimeSpan.Zero)
{
timeout = TimeSpan.MaxValue;
}
// Let Unspecified mean Local, so only convert if the source was UTC.
//
// Converge on Local instead of UTC because OpenSSL is going to assume we gave it
// local time.
if (verificationTime.Kind == DateTimeKind.Utc)
{
verificationTime = verificationTime.ToLocalTime();
}
TimeSpan remainingDownloadTime = timeout;
var leaf = new X509Certificate2(cert.Handle);
var downloaded = new HashSet<X509Certificate2>();
var systemTrusted = new HashSet<X509Certificate2>();
HashSet<X509Certificate2> candidates = OpenSslX509ChainProcessor.FindCandidates(
leaf,
extraStore,
downloaded,
systemTrusted,
ref remainingDownloadTime);
IChainPal chain = OpenSslX509ChainProcessor.BuildChain(
leaf,
candidates,
downloaded,
systemTrusted,
applicationPolicy,
certificatePolicy,
revocationMode,
revocationFlag,
verificationTime,
ref remainingDownloadTime);
if (chain.ChainStatus.Length == 0 && downloaded.Count > 0)
{
SaveIntermediateCertificates(chain.ChainElements, downloaded);
}
return chain;
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:57,代码来源:ChainPal.cs
示例3: BuildChain
/// <summary>
/// Does not throw on error. Returns null ChainPal instead.
/// </summary>
public static ChainPal BuildChain(
bool useMachineContext,
ICertificatePal cert,
X509Certificate2Collection extraStore,
OidCollection applicationPolicy,
OidCollection certificatePolicy,
X509RevocationMode revocationMode,
X509RevocationFlag revocationFlag,
DateTime verificationTime,
TimeSpan timeout)
{
CertificatePal certificatePal = (CertificatePal)cert;
unsafe
{
using (SafeCertStoreHandle extraStoreHandle = ConvertExtraStoreToSafeHandle(extraStore))
{
CERT_CHAIN_PARA chainPara = new CERT_CHAIN_PARA();
chainPara.cbSize = Marshal.SizeOf<CERT_CHAIN_PARA>();
int applicationPolicyCount;
using (SafeHandle applicationPolicyOids = applicationPolicy.ToLpstrArray(out applicationPolicyCount))
{
if (!applicationPolicyOids.IsInvalid)
{
chainPara.RequestedUsage.dwType = CertUsageMatchType.USAGE_MATCH_TYPE_AND;
chainPara.RequestedUsage.Usage.cUsageIdentifier = applicationPolicyCount;
chainPara.RequestedUsage.Usage.rgpszUsageIdentifier = applicationPolicyOids.DangerousGetHandle();
}
int certificatePolicyCount;
using (SafeHandle certificatePolicyOids = certificatePolicy.ToLpstrArray(out certificatePolicyCount))
{
if (!certificatePolicyOids.IsInvalid)
{
chainPara.RequestedIssuancePolicy.dwType = CertUsageMatchType.USAGE_MATCH_TYPE_AND;
chainPara.RequestedIssuancePolicy.Usage.cUsageIdentifier = certificatePolicyCount;
chainPara.RequestedIssuancePolicy.Usage.rgpszUsageIdentifier = certificatePolicyOids.DangerousGetHandle();
}
chainPara.dwUrlRetrievalTimeout = (int)Math.Floor(timeout.TotalMilliseconds);
FILETIME ft = FILETIME.FromDateTime(verificationTime);
CertChainFlags flags = MapRevocationFlags(revocationMode, revocationFlag);
ChainEngine chainEngine = useMachineContext ? ChainEngine.HCCE_LOCAL_MACHINE : ChainEngine.HCCE_CURRENT_USER;
SafeX509ChainHandle chain;
if (!Interop.crypt32.CertGetCertificateChain(chainEngine, certificatePal.CertContext, &ft, extraStoreHandle, ref chainPara, flags, IntPtr.Zero, out chain))
return null;
return new ChainPal(chain);
}
}
}
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:58,代码来源:ChainPal.BuildChain.cs
示例4: DecodePublicKey
public AsymmetricAlgorithm DecodePublicKey(Oid oid, byte[] encodedKeyValue, byte[] encodedParameters, ICertificatePal certificatePal)
{
switch (oid.Value)
{
case Oids.RsaRsa:
return BuildRsaPublicKey(encodedKeyValue);
}
// NotSupportedException is what desktop and CoreFx-Windows throw in this situation.
throw new NotSupportedException(SR.NotSupported_KeyAlgorithm);
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:11,代码来源:OpenSslX509Encoder.cs
示例5: BuildChain
public static IChainPal BuildChain(
bool useMachineContext,
ICertificatePal cert,
X509Certificate2Collection extraStore,
OidCollection applicationPolicy,
OidCollection certificatePolicy,
X509RevocationMode revocationMode,
X509RevocationFlag revocationFlag,
DateTime verificationTime,
TimeSpan timeout)
{
return new OpenSslX509ChainProcessor();
}
开发者ID:johnhhm,项目名称:corefx,代码行数:13,代码来源:ChainPal.cs
示例6: TryReadX509Der
internal static bool TryReadX509Der(byte[] rawData, out ICertificatePal certPal)
{
SafeX509Handle certHandle = Interop.Crypto.DecodeX509(rawData, rawData.Length);
if (certHandle.IsInvalid)
{
certHandle.Dispose();
certPal = null;
return false;
}
certPal = new OpenSslX509CertificateReader(certHandle);
return true;
}
开发者ID:dotnet,项目名称:corefx,代码行数:14,代码来源:CertificatePal.cs
示例7: FromCertificate
public static IExportPal FromCertificate(ICertificatePal cert)
{
CertificatePal certificatePal = (CertificatePal)cert;
SafeCertStoreHandle certStore = Interop.crypt32.CertOpenStore(
CertStoreProvider.CERT_STORE_PROV_MEMORY,
CertEncodingType.All,
IntPtr.Zero,
CertStoreFlags.CERT_STORE_ENUM_ARCHIVED_FLAG | CertStoreFlags.CERT_STORE_CREATE_NEW_FLAG | CertStoreFlags.CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG,
null);
if (certStore.IsInvalid)
throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
if (!Interop.crypt32.CertAddCertificateLinkToStore(certStore, certificatePal.CertContext, CertStoreAddDisposition.CERT_STORE_ADD_ALWAYS, IntPtr.Zero))
throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
return new StorePal(certStore);
}
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:StorePal.Import.cs
示例8: DecodePublicKey
public AsymmetricAlgorithm DecodePublicKey(Oid oid, byte[] encodedKeyValue, byte[] encodedParameters, ICertificatePal certificatePal)
{
if (oid.Value == Oids.Ecc && certificatePal != null)
{
return ((OpenSslX509CertificateReader)certificatePal).GetECDsaPublicKey();
}
switch (oid.Value)
{
case Oids.RsaRsa:
return BuildRsaPublicKey(encodedKeyValue);
}
// NotSupportedException is what desktop and CoreFx-Windows throw in this situation.
throw new NotSupportedException(SR.NotSupported_KeyAlgorithm);
}
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:OpenSslX509Encoder.cs
示例9: Remove
public void Remove(ICertificatePal certificate)
{
unsafe
{
SafeCertContextHandle existingCertContext = ((CertificatePal)certificate).CertContext;
SafeCertContextHandle enumCertContext = null;
CERT_CONTEXT* pCertContext = existingCertContext.CertContext;
if (!Interop.crypt32.CertFindCertificateInStore(_certStore, CertFindType.CERT_FIND_EXISTING, pCertContext, ref enumCertContext))
return; // The certificate is not present in the store, simply return.
CERT_CONTEXT* pCertContextToDelete = enumCertContext.Disconnect(); // CertDeleteCertificateFromContext always frees the context (even on error)
if (!Interop.crypt32.CertDeleteCertificateFromStore(pCertContextToDelete))
throw Marshal.GetLastWin32Error().ToCryptographicException();
GC.KeepAlive(existingCertContext);
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:17,代码来源:StorePal.cs
示例10: TryReadPkcs7Der
private static bool TryReadPkcs7Der(
byte[] rawData,
bool single,
out ICertificatePal certPal,
out List<ICertificatePal> certPals)
{
using (SafePkcs7Handle pkcs7 = Interop.Crypto.DecodePkcs7(rawData, rawData.Length))
{
if (pkcs7.IsInvalid)
{
certPal = null;
certPals = null;
return false;
}
return TryReadPkcs7(pkcs7, single, out certPal, out certPals);
}
}
开发者ID:JonHanna,项目名称:corefx,代码行数:18,代码来源:PkcsFormatReader.cs
示例11: BuildChain
public static IChainPal BuildChain(
bool useMachineContext,
ICertificatePal cert,
X509Certificate2Collection extraStore,
OidCollection applicationPolicy,
OidCollection certificatePolicy,
X509RevocationMode revocationMode,
X509RevocationFlag revocationFlag,
DateTime verificationTime,
TimeSpan timeout)
{
CheckRevocationMode(revocationMode);
// An input value of 0 on the timeout is "take all the time you need".
if (timeout == TimeSpan.Zero)
{
timeout = TimeSpan.MaxValue;
}
TimeSpan remainingDownloadTime = timeout;
X509Certificate2 leaf = new X509Certificate2(cert.Handle);
List<X509Certificate2> downloaded = new List<X509Certificate2>();
List<X509Certificate2> candidates = OpenSslX509ChainProcessor.FindCandidates(
leaf,
extraStore,
downloaded,
ref remainingDownloadTime);
IChainPal chain = OpenSslX509ChainProcessor.BuildChain(
leaf,
candidates,
downloaded,
applicationPolicy,
certificatePolicy,
verificationTime);
if (chain.ChainStatus.Length == 0 && downloaded.Count > 0)
{
SaveIntermediateCertificates(chain.ChainElements, downloaded);
}
return chain;
}
开发者ID:nelsonsar,项目名称:corefx,代码行数:44,代码来源:ChainPal.cs
示例12: TryReadPkcs7Der
private static bool TryReadPkcs7Der(
SafeBioHandle bio,
bool single,
out ICertificatePal certPal,
out List<ICertificatePal> certPals)
{
SafePkcs7Handle pkcs7 = Interop.libcrypto.d2i_PKCS7_bio(bio, IntPtr.Zero);
if (pkcs7.IsInvalid)
{
certPal = null;
certPals = null;
return false;
}
using (pkcs7)
{
return TryReadPkcs7(pkcs7, single, out certPal, out certPals);
}
}
开发者ID:AdityaTulasi,项目名称:corefx,代码行数:20,代码来源:PkcsFormatReader.cs
示例13: TryReadPkcs7Der
private static unsafe bool TryReadPkcs7Der(
byte[] rawData,
bool single,
out ICertificatePal certPal,
out List<ICertificatePal> certPals)
{
SafePkcs7Handle pkcs7 = Interop.libcrypto.OpenSslD2I(
(ptr, b, i) => Interop.libcrypto.d2i_PKCS7(ptr, b, i),
rawData,
checkHandle: false);
if (pkcs7.IsInvalid)
{
certPal = null;
certPals = null;
return false;
}
using (pkcs7)
{
return TryReadPkcs7(pkcs7, single, out certPal, out certPals);
}
}
开发者ID:nblumhardt,项目名称:corefx,代码行数:23,代码来源:PkcsFormatReader.cs
示例14: TryReadPkcs7Pem
private static bool TryReadPkcs7Pem(
byte[] rawData,
bool single,
out ICertificatePal certPal,
out List<ICertificatePal> certPals)
{
using (SafeBioHandle bio = Interop.Crypto.CreateMemoryBio())
{
Interop.Crypto.CheckValidOpenSslHandle(bio);
Interop.Crypto.BioWrite(bio, rawData, rawData.Length);
return TryReadPkcs7Pem(bio, single, out certPal, out certPals);
}
}
开发者ID:JonHanna,项目名称:corefx,代码行数:15,代码来源:PkcsFormatReader.cs
示例15: FromCertificate
public static IStorePal FromCertificate(ICertificatePal cert)
{
ICertificatePal duplicatedHandles = ((OpenSslX509CertificateReader)cert).DuplicateHandles();
return new CollectionBackedStoreProvider(new X509Certificate2(duplicatedHandles));
}
开发者ID:rajeevkb,项目名称:corefx,代码行数:6,代码来源:StorePal.cs
示例16: SingleCertToStorePal
private static IStorePal SingleCertToStorePal(ICertificatePal singleCert)
{
return new CollectionBackedStoreProvider(new X509Certificate2(singleCert));
}
开发者ID:rajeevkb,项目名称:corefx,代码行数:4,代码来源:StorePal.cs
示例17: Remove
public void Remove(ICertificatePal certPal)
{
OpenSslX509CertificateReader cert = (OpenSslX509CertificateReader)certPal;
using (X509Certificate2 copy = new X509Certificate2(cert.DuplicateHandles()))
{
bool hadCandidates;
string currentFilename = FindExistingFilename(copy, _storePath, out hadCandidates);
if (currentFilename != null)
{
if (_readOnly)
{
// Windows compatibility, the readonly check isn't done until after a match is found.
throw new CryptographicException(SR.Cryptography_X509_StoreReadOnly);
}
File.Delete(currentFilename);
}
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:21,代码来源:DirectoryBasedStoreProvider.cs
示例18: Add
public void Add(ICertificatePal certPal)
{
if (_readOnly)
{
// Windows compatibility: Remove only throws when it needs to do work, add throws always.
throw new CryptographicException(SR.Cryptography_X509_StoreReadOnly);
}
// This may well be the first time that we've added something to this store.
Directory.CreateDirectory(_storePath);
uint userId = Interop.Sys.GetEUid();
EnsureDirectoryPermissions(_storePath, userId);
OpenSslX509CertificateReader cert = (OpenSslX509CertificateReader)certPal;
using (X509Certificate2 copy = new X509Certificate2(cert.DuplicateHandles()))
{
string thumbprint = copy.Thumbprint;
bool findOpenSlot;
// The odds are low that we'd have a thumbprint collision, but check anyways.
string existingFilename = FindExistingFilename(copy, _storePath, out findOpenSlot);
if (existingFilename != null)
{
if (!copy.HasPrivateKey)
{
return;
}
try
{
using (X509Certificate2 fromFile = new X509Certificate2(existingFilename))
{
if (fromFile.HasPrivateKey)
{
// We have a private key, the file has a private key, we're done here.
return;
}
}
}
catch (CryptographicException)
{
// We can't read this file anymore, but a moment ago it was this certificate,
// so go ahead and overwrite it.
}
}
string destinationFilename;
FileMode mode = FileMode.CreateNew;
if (existingFilename != null)
{
destinationFilename = existingFilename;
mode = FileMode.Create;
}
else if (findOpenSlot)
{
destinationFilename = FindOpenSlot(thumbprint);
}
else
{
destinationFilename = Path.Combine(_storePath, thumbprint + PfxExtension);
}
using (FileStream stream = new FileStream(destinationFilename, mode))
{
EnsureFilePermissions(stream, userId);
byte[] pkcs12 = copy.Export(X509ContentType.Pkcs12);
stream.Write(pkcs12, 0, pkcs12.Length);
}
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:74,代码来源:DirectoryBasedStoreProvider.cs
示例19: TryReadPkcs12
private static bool TryReadPkcs12(
OpenSslPkcs12Reader pfx,
string password,
bool single,
out ICertificatePal readPal,
out List<ICertificatePal> readCerts)
{
pfx.Decrypt(password);
ICertificatePal first = null;
List<ICertificatePal> certs = null;
if (!single)
{
certs = new List<ICertificatePal>();
}
foreach (OpenSslX509CertificateReader certPal in pfx.ReadCertificates())
{
if (single)
{
// When requesting an X509Certificate2 from a PFX only the first entry is
// returned. Other entries should be disposed.
if (first == null)
{
first = certPal;
}
else if (certPal.HasPrivateKey && !first.HasPrivateKey)
{
first.Dispose();
first = certPal;
}
else
{
certPal.Dispose();
}
}
else
{
certs.Add(certPal);
}
}
readPal = first;
readCerts = certs;
return true;
}
开发者ID:JonHanna,项目名称:corefx,代码行数:48,代码来源:PkcsFormatReader.cs
示例20: TryReadX509Pem
internal static bool TryReadX509Pem(SafeBioHandle bio, out ICertificatePal certPal)
{
SafeX509Handle cert = Interop.Crypto.PemReadX509FromBio(bio);
if (cert.IsInvalid)
{
cert.Dispose();
certPal = null;
return false;
}
certPal = new OpenSslX509CertificateReader(cert);
return true;
}
开发者ID:Corillian,项目名称:corefx,代码行数:14,代码来源:CertificatePal.cs
注:本文中的ICertificatePal类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论