本文整理匯總了C#中Org.BouncyCastle.X509.X509Certificate.GetTbsCertificate方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Certificate.GetTbsCertificate方法的具體用法?C# X509Certificate.GetTbsCertificate怎麽用?C# X509Certificate.GetTbsCertificate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Org.BouncyCastle.X509.X509Certificate
的用法示例。
在下文中一共展示了X509Certificate.GetTbsCertificate方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetSubjectX509Principal
/// <summary>Return the subject of the given cert as an X509Principal.</summary>
public static X509Name GetSubjectX509Principal(
X509Certificate cert)
{
try
{
TbsCertificateStructure tbsCert = TbsCertificateStructure.GetInstance(
Asn1Object.FromByteArray(cert.GetTbsCertificate()));
return tbsCert.Subject;
}
catch (Exception e)
{
throw new CertificateEncodingException("Could not extract subject", e);
}
}
示例2: IsSignedBy
public static bool IsSignedBy(this X509Certificate thisCertificate, X509Certificate signerCertificate)
{
X509Certificate2 c = new X509Certificate2(thisCertificate.GetTbsCertificate());
X509Certificate2 i = new X509Certificate2(signerCertificate.GetTbsCertificate());
X509Certificate2 c2 = new X509Certificate2(@"c:\temp\der.cer");
X509Certificate2 i2 = new X509Certificate2(@"c:\temp\cader.cer");
/*byte[] pvSubject = thisCertificate.GetTbsCertificate();
byte[] pvIssuer = signerCertificate.GetTbsCertificate();
*/
System.Text.Encoding.ASCII.GetString(c.RawData);
IntPtr pvSubject = c.Handle;
IntPtr pvIssuer = i.Handle;
int res = SspiProvider.CryptVerifyCertificateSignatureEx(IntPtr.Zero, X509_ASN_ENCODING,
CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT, pvSubject,
CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, pvIssuer, 0,
IntPtr.Zero);
Marshal.GetLastWin32Error();
CmsSigner signer = new CmsSigner(i);
SignedCms signedMessage = new SignedCms();
// deserialize PKCS #7 byte array
signedMessage.Decode(thisCertificate.GetTbsCertificate());
Log.Write("Veryfy old");
Log.Write("EndVeryfy old");
Log.Write("Get signer's public key");
var publicKey = signerCertificate.GetPublicKey();
Log.Write("Got signer's public key");
try
{
Log.Write("Veryfy signature");
//TODO: log errors
thisCertificate.Verify(publicKey);
Log.Write("Verified");
}
catch (CertificateException)
{
return false;
}
catch (InvalidKeyException)
{
return false;
}
return true;
}
示例3: GetSubjectFields
/**
* Get the subject fields from an X509 Certificate
* @param cert an X509Certificate
* @return an X509Name
*/
public static X509Name GetSubjectFields(X509Certificate cert) {
return new X509Name((Asn1Sequence)GetSubject(cert.GetTbsCertificate()));
}
示例4: ComputeRecipientInfo
private KeyTransRecipientInfo ComputeRecipientInfo(X509Certificate x509certificate, byte[] abyte0) {
Asn1InputStream asn1inputstream =
new Asn1InputStream(new MemoryStream(x509certificate.GetTbsCertificate()));
TbsCertificateStructure tbscertificatestructure =
TbsCertificateStructure.GetInstance(asn1inputstream.ReadObject());
AlgorithmIdentifier algorithmidentifier = tbscertificatestructure.SubjectPublicKeyInfo.AlgorithmID;
Org.BouncyCastle.Asn1.Cms.IssuerAndSerialNumber issuerandserialnumber =
new Org.BouncyCastle.Asn1.Cms.IssuerAndSerialNumber(
tbscertificatestructure.Issuer,
tbscertificatestructure.SerialNumber.Value);
IBufferedCipher cipher = CipherUtilities.GetCipher(algorithmidentifier.ObjectID);
cipher.Init(true, x509certificate.GetPublicKey());
byte[] outp = new byte[10000];
int len = cipher.DoFinal(abyte0, outp, 0);
byte[] abyte1 = new byte[len];
System.Array.Copy(outp, 0, abyte1, 0, len);
DerOctetString deroctetstring = new DerOctetString(abyte1);
RecipientIdentifier recipId = new RecipientIdentifier(issuerandserialnumber);
return new KeyTransRecipientInfo( recipId, algorithmidentifier, deroctetstring);
}
示例5: GetTbsCertificateStructure
internal static TbsCertificateStructure GetTbsCertificateStructure(X509Certificate cert)
{
return TbsCertificateStructure.GetInstance(Asn1Object.FromByteArray(cert.GetTbsCertificate()));
}
示例6: RecipientInf
internal RecipientInf(
X509Certificate cert)
{
this.cert = cert;
this.pubKey = cert.GetPublicKey();
try
{
TbsCertificateStructure tbs = TbsCertificateStructure.GetInstance(
Asn1Object.FromByteArray(cert.GetTbsCertificate()));
keyEncAlg = tbs.SubjectPublicKeyInfo.AlgorithmID;
}
// catch (IOException e)
catch (Exception)
{
throw new ArgumentException("can't extract key algorithm from this cert");
}
// catch (CertificateEncodingException)
// {
// throw new ArgumentException("can't extract tbs structure from this cert");
// }
}