本文整理匯總了C#中Org.BouncyCastle.X509.X509Certificate.GetExtensionValue方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Certificate.GetExtensionValue方法的具體用法?C# X509Certificate.GetExtensionValue怎麽用?C# X509Certificate.GetExtensionValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Org.BouncyCastle.X509.X509Certificate
的用法示例。
在下文中一共展示了X509Certificate.GetExtensionValue方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ValidateCertificate
/**
* Validate the passed in certificate as being of the correct type to be used
* for time stamping. To be valid it must have an ExtendedKeyUsage extension
* which has a key purpose identifier of id-kp-timeStamping.
*
* @param cert the certificate of interest.
* @throws TspValidationException if the certicate fails on one of the check points.
*/
public static void ValidateCertificate(
X509Certificate cert)
{
if (cert.Version != 3)
throw new ArgumentException("Certificate must have an ExtendedKeyUsage extension.");
Asn1OctetString ext = cert.GetExtensionValue(X509Extensions.ExtendedKeyUsage);
if (ext == null)
throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension.");
if (!cert.GetCriticalExtensionOids().Contains(X509Extensions.ExtendedKeyUsage.Id))
throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
try
{
ExtendedKeyUsage extKey = ExtendedKeyUsage.GetInstance(
Asn1Object.FromByteArray(ext.GetOctets()));
if (!extKey.HasKeyPurposeId(KeyPurposeID.IdKPTimeStamping) || extKey.Count != 1)
throw new TspValidationException("ExtendedKeyUsage not solely time stamping.");
}
catch (IOException)
{
throw new TspValidationException("cannot process ExtendedKeyUsage extension");
}
}
示例2: GetExtensionValue
protected static Asn1Object GetExtensionValue(X509Certificate cert,
string oid)
{
if (cert == null)
{
return null;
}
byte[] bytes = cert.GetExtensionValue(new DerObjectIdentifier(oid)).GetOctets();
if (bytes == null)
{
return null;
}
Asn1InputStream aIn = new Asn1InputStream(bytes);
return aIn.ReadObject();
}
示例3: GetExtensionValue
private static Asn1Object GetExtensionValue(X509Certificate cert, String oid) {
byte[] bytes = cert.GetExtensionValue(new DerObjectIdentifier(oid)).GetDerEncoded();
if (bytes == null) {
return null;
}
Asn1InputStream aIn = new Asn1InputStream(new MemoryStream(bytes));
Asn1OctetString octs = (Asn1OctetString) aIn.ReadObject();
aIn = new Asn1InputStream(new MemoryStream(octs.GetOctets()));
return aIn.ReadObject();
}
示例4: GetTSAURL
// Time Stamp Authority
/**
* Gets the URL of the TSA if it's available on the certificate
* @param certificate a certificate
* @return a TSA URL
* @throws IOException
*/
public static String GetTSAURL(X509Certificate certificate) {
Asn1OctetString octetString = certificate.GetExtensionValue(SecurityIDs.ID_TSA);
if (octetString == null)
return null;
byte[] der = octetString.GetOctets();
if (der == null)
return null;
Asn1Object asn1obj;
try {
asn1obj = Asn1Object.FromByteArray(der);
if (asn1obj is DerOctetString) {
DerOctetString octets = (DerOctetString) asn1obj;
asn1obj = Asn1Object.FromByteArray(octets.GetOctets());
}
Asn1Sequence asn1seq = Asn1Sequence.GetInstance(asn1obj);
return GetStringFromGeneralName(asn1seq[1].ToAsn1Object());
} catch (IOException) {
return null;
}
}
示例5: CopyAndAddExtension
/**
* add a given extension field for the standard extensions tag (tag 3)
* copying the extension value from another certificate.
* @throws CertificateParsingException if the extension cannot be extracted.
*/
public void CopyAndAddExtension(
DerObjectIdentifier oid,
bool critical,
X509Certificate cert)
{
Asn1OctetString extValue = cert.GetExtensionValue(oid);
if (extValue == null)
{
throw new CertificateParsingException("extension " + oid + " not present");
}
try
{
Asn1Encodable value = X509ExtensionUtilities.FromExtensionValue(extValue);
this.AddExtension(oid, critical, value);
}
catch (Exception e)
{
throw new CertificateParsingException(e.Message, e);
}
}
示例6: ObtenerValorDeExtension
protected static Asn1Object ObtenerValorDeExtension(X509Certificate in_Certificado,
string oid)
{
if (in_Certificado == null)
{
return null;
}
byte[] bytes = in_Certificado.GetExtensionValue(new DerObjectIdentifier(oid)).GetOctets();
if (bytes == null)
{
return null;
}
Asn1InputStream aIn = new Asn1InputStream(bytes);
return aIn.ReadObject();
}
示例7: Init
private void Init()
{
try
{
trustedCert = certParser.ReadCertificate(Base64.Decode(Trust_Anchor_CP_01_01_crt));
trustedCRL = crlParser.ReadCrl(Base64.Decode(Trust_Anchor_CRL_CP_01_01_crl));
trustedSet = new HashSet();
byte[] _ncBytes = null;
Asn1OctetString _oct = trustedCert.GetExtensionValue(X509Extensions.NameConstraints);
if (_oct != null)
{
_ncBytes = _oct.GetOctets();
}
trustedSet.Add(new TrustAnchor(trustedCert, _ncBytes));
testCount = 0;
testFail = new ArrayList();
resultBuf = new StringBuilder("\n");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
示例8: GetCertificateInfo
public static CertificateInfo GetCertificateInfo(byte[] certificate, TCertificateFormat certificateFormat)
{
CertificateInfo result = null;
X509CertificateStructure cert = null;
switch (certificateFormat)
{
case TCertificateFormat.NotSet:
break;
case TCertificateFormat.PEM:
Org.BouncyCastle.Utilities.IO.Pem.PemReader reader = new Org.BouncyCastle.Utilities.IO.Pem.PemReader(new StreamReader(new MemoryStream(certificate)));
Org.BouncyCastle.Utilities.IO.Pem.PemObject pem = reader.ReadPemObject();
while (pem != null)
{
if (pem.Type.EndsWith("CERTIFICATE"))
{
cert = X509CertificateStructure.GetInstance(pem.Content);
}
else if (pem.Type.EndsWith("PRIVATE KEY"))
{
if (result == null)
result = new CertificateInfo();
result.PrivateKey = GetPrivateKeyFromPEM(pem);
}
pem = reader.ReadPemObject();
}
break;
case TCertificateFormat.PFX:
break;
case TCertificateFormat.CER:
cert = X509CertificateStructure.GetInstance(certificate);
break;
default:
break;
}
if (cert != null)
{
if (result == null)
result = new CertificateInfo();
result.Subject = new CertificateSubject(cert);
X509Certificate certX509 = new X509Certificate(cert);
Asn1OctetString subjectKeyID = certX509.GetExtensionValue(X509Extensions.SubjectKeyIdentifier);
if (subjectKeyID != null)
{
byte[] encodeKeyID = subjectKeyID.GetOctets();
byte[] keyID = new byte[encodeKeyID[1]];
Buffer.BlockCopy(encodeKeyID, 2, keyID, 0, encodeKeyID[1]);
result.SubjectKeyID = keyID;
}
}
return result;
}