java.security.cert.X509Certificate.verify()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(488)

本文整理了Java中java.security.cert.X509Certificate.verify()方法的一些代码示例,展示了X509Certificate.verify()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。X509Certificate.verify()方法的具体详情如下:
包路径:java.security.cert.X509Certificate
类名称:X509Certificate
方法名:verify

X509Certificate.verify介绍

暂无

代码示例

代码示例来源:origin: Meituan-Dianping/walle

@Override
public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException,
    InvalidKeyException, NoSuchProviderException, SignatureException {
  mDelegate.verify(key);
}

代码示例来源:origin: Meituan-Dianping/walle

@Override
public void verify(PublicKey key, String sigProvider)
    throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
    NoSuchProviderException, SignatureException {
  mDelegate.verify(key, sigProvider);
}

代码示例来源:origin: square/okhttp

/** Returns the trusted CA certificate that signed {@code cert}. */
private X509Certificate findByIssuerAndSignature(X509Certificate cert) {
 X500Principal issuer = cert.getIssuerX500Principal();
 Set<X509Certificate> subjectCaCerts = subjectToCaCerts.get(issuer);
 if (subjectCaCerts == null) return null;
 for (X509Certificate caCert : subjectCaCerts) {
  PublicKey publicKey = caCert.getPublicKey();
  try {
   cert.verify(publicKey);
   return caCert;
  } catch (Exception ignored) {
  }
 }
 return null;
}

代码示例来源:origin: square/okhttp

/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */
private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) {
 if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false;
 try {
  toVerify.verify(signingCert.getPublicKey());
  return true;
 } catch (GeneralSecurityException verifyFailed) {
  return false;
 }
}

代码示例来源:origin: prestodb/presto

@Override public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
 X500Principal issuer = cert.getIssuerX500Principal();
 Set<X509Certificate> subjectCaCerts = subjectToCaCerts.get(issuer);
 if (subjectCaCerts == null) return null;
 for (X509Certificate caCert : subjectCaCerts) {
  PublicKey publicKey = caCert.getPublicKey();
  try {
   cert.verify(publicKey);
   return caCert;
  } catch (Exception ignored) {
  }
 }
 return null;
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Returns true if the specified certificate is a self-signed certificate.
 *
 * @return true if the specified certificate is a self-signed certificate.
 */
public static boolean isSelfSignedCertificate(X509Certificate certificate) {
  try {
    certificate.verify(certificate.getPublicKey());
    return true;
  } catch (GeneralSecurityException e) {
    return false;
  }
}

代码示例来源:origin: prestodb/presto

/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */
private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) {
 if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false;
 try {
  toVerify.verify(signingCert.getPublicKey());
  return true;
 } catch (GeneralSecurityException verifyFailed) {
  return false;
 }
}

代码示例来源:origin: redisson/redisson

@Override
public void verify(PublicKey key, String sigProvider)
    throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
    NoSuchProviderException, SignatureException {
  unwrap().verify(key, sigProvider);
}

代码示例来源:origin: redisson/redisson

@Override
public void verify(PublicKey key)
    throws CertificateException, NoSuchAlgorithmException,
    InvalidKeyException, NoSuchProviderException, SignatureException {
  unwrap().verify(key);
}

代码示例来源:origin: redisson/redisson

public void verify(PublicKey key, Provider sigProvider)
    throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
  unwrap().verify(key, sigProvider);
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

@Override public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
 X500Principal issuer = cert.getIssuerX500Principal();
 Set<X509Certificate> subjectCaCerts = subjectToCaCerts.get(issuer);
 if (subjectCaCerts == null) return null;
 for (X509Certificate caCert : subjectCaCerts) {
  PublicKey publicKey = caCert.getPublicKey();
  try {
   cert.verify(publicKey);
   return caCert;
  } catch (Exception ignored) {
  }
 }
 return null;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */
private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) {
 if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false;
 try {
  toVerify.verify(signingCert.getPublicKey());
  return true;
 } catch (GeneralSecurityException verifyFailed) {
  return false;
 }
}

代码示例来源:origin: wildfly/wildfly

@Override
public void verify(PublicKey key)
    throws CertificateException, NoSuchAlgorithmException,
    InvalidKeyException, NoSuchProviderException, SignatureException {
  unwrap().verify(key);
}

代码示例来源:origin: wildfly/wildfly

@Override
public void verify(PublicKey key, String sigProvider)
    throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
    NoSuchProviderException, SignatureException {
  unwrap().verify(key, sigProvider);
}

代码示例来源:origin: wildfly/wildfly

private static boolean issuedBy(final X509Certificate certificate, X509Certificate issuer) {
  if (issuer.getSubjectDN().equals(certificate.getIssuerDN())) {
    try {
      certificate.verify(issuer.getPublicKey());
      return true;
    } catch (Exception e) {
      return false;
    }
  }
  return false;
}

代码示例来源:origin: robovm/robovm

public void verify(PublicKey key, String sigProvider)
        throws CertificateException,
          NoSuchAlgorithmException, InvalidKeyException,
          NoSuchProviderException, SignatureException {
  try {
    cert.verify(key, sigProvider);
  } catch (java.security.cert.CertificateException e) {
    throw new CertificateException(e.getMessage());
  }
}

代码示例来源:origin: robovm/robovm

public void verify(PublicKey key) throws CertificateException,
          NoSuchAlgorithmException, InvalidKeyException,
          NoSuchProviderException, SignatureException {
  try {
    cert.verify(key);
  } catch (java.security.cert.CertificateException e) {
    throw new CertificateException(e.getMessage());
  }
}

代码示例来源:origin: redisson/redisson

static String[] generate(String fqdn, KeyPair keypair, SecureRandom random, Date notBefore, Date notAfter)
    throws Exception {
  PrivateKey key = keypair.getPrivate();
  // Prepare the information required for generating an X.509 certificate.
  X500Name owner = new X500Name("CN=" + fqdn);
  X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(
      owner, new BigInteger(64, random), notBefore, notAfter, owner, keypair.getPublic());
  ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(key);
  X509CertificateHolder certHolder = builder.build(signer);
  X509Certificate cert = new JcaX509CertificateConverter().setProvider(PROVIDER).getCertificate(certHolder);
  cert.verify(keypair.getPublic());
  return newSelfSignedCertificate(fqdn, key, cert);
}

代码示例来源:origin: wildfly/wildfly

static String[] generate(String fqdn, KeyPair keypair, SecureRandom random, Date notBefore, Date notAfter)
    throws Exception {
  PrivateKey key = keypair.getPrivate();
  // Prepare the information required for generating an X.509 certificate.
  X500Name owner = new X500Name("CN=" + fqdn);
  X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(
      owner, new BigInteger(64, random), notBefore, notAfter, owner, keypair.getPublic());
  ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(key);
  X509CertificateHolder certHolder = builder.build(signer);
  X509Certificate cert = new JcaX509CertificateConverter().setProvider(PROVIDER).getCertificate(certHolder);
  cert.verify(keypair.getPublic());
  return newSelfSignedCertificate(fqdn, key, cert);
}

代码示例来源:origin: io.netty/netty

static String[] generate(String fqdn, KeyPair keypair, SecureRandom random) throws Exception {
  PrivateKey key = keypair.getPrivate();
  // Prepare the information required for generating an X.509 certificate.
  X500Name owner = new X500Name("CN=" + fqdn);
  X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(
      owner, new BigInteger(64, random), NOT_BEFORE, NOT_AFTER, owner, keypair.getPublic());
  ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(key);
  X509CertificateHolder certHolder = builder.build(signer);
  X509Certificate cert = new JcaX509CertificateConverter().setProvider(PROVIDER).getCertificate(certHolder);
  cert.verify(keypair.getPublic());
  return newSelfSignedCertificate(fqdn, key, cert);
}

相关文章