本文整理匯總了C#中Org.BouncyCastle.X509.X509Certificate.GetPublicKey方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Certificate.GetPublicKey方法的具體用法?C# X509Certificate.GetPublicKey怎麽用?C# X509Certificate.GetPublicKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Org.BouncyCastle.X509.X509Certificate
的用法示例。
在下文中一共展示了X509Certificate.GetPublicKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: IsSignedBy
public virtual bool IsSignedBy(X509Certificate potentialIssuer)
{
try
{
GetCertificate().Verify(potentialIssuer.GetPublicKey());
return true;
}
catch (InvalidKeyException)
{
return false;
}
catch (CertificateException)
{
return false;
}
catch (NoSuchAlgorithmException)
{
return false;
}
/*catch (NoSuchProviderException e)
{
throw new RuntimeException(e);
}*/
catch (SignatureException)
{
return false;
}
}
示例2: SecureMimeDigitalCertificate
internal SecureMimeDigitalCertificate(X509Certificate certificate)
{
Certificate = certificate;
var pubkey = certificate.GetPublicKey ();
if (pubkey is DsaKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.Dsa;
else if (pubkey is RsaKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.RsaGeneral;
else if (pubkey is ElGamalKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.ElGamalGeneral;
else if (pubkey is ECKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.EllipticCurve;
else if (pubkey is DHKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.DiffieHellman;
var encoded = certificate.GetEncoded ();
var fingerprint = new StringBuilder ();
var sha1 = new Sha1Digest ();
var data = new byte[20];
sha1.BlockUpdate (encoded, 0, encoded.Length);
sha1.DoFinal (data, 0);
for (int i = 0; i < data.Length; i++)
fingerprint.Append (data[i].ToString ("X2"));
Fingerprint = fingerprint.ToString ();
}
示例3: IsSignedBy
public virtual bool IsSignedBy(X509Certificate potentialIssuer)
{
try
{
//return ocspResp.Verify(potentialIssuer.GetPublicKey(), "BC");
return ocspResp.Verify(potentialIssuer.GetPublicKey());
}
/*catch (NoSuchProviderException e)
{
throw new RuntimeException(e);
}*/
catch (OcspException)
{
return false;
}
}
示例4: SecureMimeDigitalCertificate
internal SecureMimeDigitalCertificate (X509Certificate certificate)
{
Certificate = certificate;
var pubkey = certificate.GetPublicKey ();
if (pubkey is DsaKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.Dsa;
else if (pubkey is RsaKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.RsaGeneral;
else if (pubkey is ElGamalKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.ElGamalGeneral;
else if (pubkey is ECKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.EllipticCurve;
else if (pubkey is DHKeyParameters)
PublicKeyAlgorithm = PublicKeyAlgorithm.DiffieHellman;
Fingerprint = certificate.GetFingerprint ();
}
示例5: 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;
}
示例6: CertificateID
/**
* create from an issuer certificate and the serial number of the
* certificate it signed.
* @exception OcspException if any problems occur creating the id fields.
*/
public CertificateID(
string hashAlgorithm,
X509Certificate issuerCert,
BigInteger number)
{
try
{
IDigest digest = DigestUtilities.GetDigest(hashAlgorithm);
AlgorithmIdentifier hashAlg = new AlgorithmIdentifier(
new DerObjectIdentifier(hashAlgorithm), DerNull.Instance);
X509Name issuerName = PrincipalUtilities.GetSubjectX509Principal(issuerCert);
byte[] encodedIssuerName = issuerName.GetEncoded();
digest.BlockUpdate(encodedIssuerName, 0, encodedIssuerName.Length);
byte[] hash = DigestUtilities.DoFinal(digest);
Asn1OctetString issuerNameHash = new DerOctetString(hash);
AsymmetricKeyParameter issuerKey = issuerCert.GetPublicKey();
SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(issuerKey);
byte[] encodedPublicKey = info.PublicKeyData.GetBytes();
digest.BlockUpdate(encodedPublicKey, 0, encodedPublicKey.Length);
hash = DigestUtilities.DoFinal(digest);
Asn1OctetString issuerKeyHash = new DerOctetString(hash);
DerInteger serialNumber = new DerInteger(number);
this.id = new CertID(hashAlg, issuerNameHash, issuerKeyHash, serialNumber);
}
catch (Exception e)
{
throw new OcspException("problem creating ID: " + e, e);
}
}
示例7: VerifySignature
public bool VerifySignature(X509Certificate attestationCertificate, byte[] signedBytes, byte[] signature)
{
if (attestationCertificate == null)
{
throw new ArgumentNullException(nameof(attestationCertificate));
}
if (signedBytes == null)
{
throw new ArgumentNullException(nameof(signedBytes));
}
if (signature == null)
{
throw new ArgumentNullException(nameof(signature));
}
var publicKey = attestationCertificate.GetPublicKey() as ECPublicKeyParameters;
if (publicKey == null)
{
throw new U2FException("The certificate publickey isn't an Elliptic curve");
}
return VerifySignature(publicKey, signedBytes, signature);
}
示例8: ValidateResponse
private void ValidateResponse(BasicOcspResp or, X509Certificate issuerCert)
{
ValidateResponseSignature(or, issuerCert.GetPublicKey());
ValidateSignerAuthorization(issuerCert, or.GetCerts()[0]);
}
示例9: VerifySignature
/// <summary>
/// Verify signature
/// </summary>
/// <returns>Boolean indicating success</returns>
public bool VerifySignature(byte[] data, byte[] expectedSignature, X509Certificate cert)
{
/* Init alg */
ISigner signer = SignerUtilities.GetSigner("SHA256withRSA");
/* Populate key */
signer.Init(false, cert.GetPublicKey());
/* Calculate the signature and see if it matches */
signer.BlockUpdate(data, 0, data.Length);
return signer.VerifySignature(expectedSignature);
}
示例10: CreateCertID
private static CertID CreateCertID(
AlgorithmIdentifier hashAlg,
X509Certificate issuerCert,
DerInteger serialNumber)
{
try
{
String hashAlgorithm = hashAlg.ObjectID.Id;
X509Name issuerName = PrincipalUtilities.GetSubjectX509Principal(issuerCert);
byte[] issuerNameHash = DigestUtilities.CalculateDigest(
hashAlgorithm, issuerName.GetEncoded());
AsymmetricKeyParameter issuerKey = issuerCert.GetPublicKey();
SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(issuerKey);
byte[] issuerKeyHash = DigestUtilities.CalculateDigest(
hashAlgorithm, info.PublicKeyData.GetBytes());
return new CertID(hashAlg, new DerOctetString(issuerNameHash),
new DerOctetString(issuerKeyHash), serialNumber);
}
catch (Exception e)
{
throw new OcspException("problem creating ID: " + e, e);
}
}
示例11: Verify
/**
* verify that the given certificate succesfully handles and confirms
* the signature associated with this signer and, if a signingTime
* attribute is available, that the certificate was valid at the time the
* signature was generated.
*/
public bool Verify(
X509Certificate cert)
{
Asn1.Cms.AttributeTable attr = this.SignedAttributes;
if (attr != null)
{
Asn1.Cms.Attribute t = attr[CmsAttributes.SigningTime];
if (t != null)
{
Asn1.Cms.Time time = Asn1.Cms.Time.GetInstance(
t.AttrValues[0].ToAsn1Object());
cert.CheckValidity(time.Date);
}
}
return DoVerify(cert.GetPublicKey(), attr);
}
示例12: ValidateResponse
private void ValidateResponse(BasicOcspResp in_OcspResp, X509Certificate in_CertificadoEmisor)
{
ValidarResponseSignature(in_OcspResp, in_CertificadoEmisor.GetPublicKey());
ValidarSignerAuthorization(in_CertificadoEmisor, in_OcspResp.GetCerts()[0]);
}
示例13: IsSelfSigned
private static bool IsSelfSigned(X509Certificate certificate)
{
if (!certificate.SubjectDN.Equivalent(certificate.IssuerDN))
return false;
try
{
certificate.Verify(certificate.GetPublicKey());
return true;
}
catch (SignatureException)
{
return false;
}
catch (InvalidKeyException)
{
return false;
}
}
示例14: VerifySigner
private void VerifySigner(SignerInformation signer, X509Certificate cert)
{
if (cert.GetPublicKey() is DsaPublicKeyParameters)
{
DsaPublicKeyParameters key = (DsaPublicKeyParameters)cert.GetPublicKey();
if (key.Parameters == null)
{
Assert.IsTrue(signer.Verify(GetInheritedKey(key)));
}
else
{
Assert.IsTrue(signer.Verify(cert));
}
}
else
{
Assert.IsTrue(signer.Verify(cert));
}
}
示例15: IsRequestSignatureValid
private bool IsRequestSignatureValid(X509Certificate cert, string signature, HttpRequestBase request)
{
byte[] requestBytes;
using (MemoryStream mem = new MemoryStream())
{
request.InputStream.CopyTo(mem);
request.InputStream.Position = 0;
requestBytes = mem.ToArray();
}
byte[] signatureBytes = null;
try
{
signatureBytes = Convert.FromBase64String(signature);
}
catch (FormatException)
{
return false;
}
var publicKey = (RsaKeyParameters)cert.GetPublicKey();
var signer = SignerUtilities.GetSigner("SHA1withRSA");
signer.Init(false, publicKey);
signer.BlockUpdate(requestBytes, 0, requestBytes.Length);
return signer.VerifySignature(signatureBytes);
}