当前位置: 首页>>代码示例>>Java>>正文


Java X509Certificate.getPublicKey方法代码示例

本文整理汇总了Java中java.security.cert.X509Certificate.getPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java X509Certificate.getPublicKey方法的具体用法?Java X509Certificate.getPublicKey怎么用?Java X509Certificate.getPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.cert.X509Certificate的用法示例。


在下文中一共展示了X509Certificate.getPublicKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: select

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
		throws KeySelectorException {

	for (Object o : keyInfo.getContent()) {
		if (o instanceof X509Data) {
			for (Object o2 : ((X509Data) o).getContent()) {
				if (o2 instanceof X509Certificate) {
					final X509Certificate cert = (X509Certificate) o2;
					return new KeySelectorResult() {
						public Key getKey() {
							return cert.getPublicKey();
						}
					};
				}
			}
		}
	}

	return null;
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:22,代码来源:X509CertificateKeySelector.java

示例2: findByIssuerAndSignature

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:TrustRootIndex.java

示例3: testParseKey

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Test
public void testParseKey() throws Exception {
    String cert =
            "-----BEGIN CERTIFICATE-----\nMIIDIDCCAggCAQEwDQYJKoZIhvcNAQELBQAwVjELMAkGA1UEBhMCVVMxJDAiBgNV"
                    + "\nBAoMG1N5bXBob255IENvbW11bmljYXRpb25zIExMQzEhMB8GA1UEAwwYVHJ1c3Rl"
                    + "\nZCBDQSBSb290IGZvciBQb2QgMB4XDTE1MDUyOTIzMDIxOFoXDTI1MDIyNTIzMDIx"
                    + "\nOFowVjELMAkGA1UEBhMCVVMxJDAiBgNVBAoMG1N5bXBob255IENvbW11bmljYXRp"
                    + "\nb25zIExMQzEhMB8GA1UEAwwYVHJ1c3RlZCBDQSBSb290IGZvciBQb2QgMIIBIjAN"
                    + "\nBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1NrtXHImJv2KQp5EOA2+s0Q2NQ0M\nKUA2f/FO5f0"
                    + "+pnYtovDYYhNZG4pKbDCw6efBCCkts+9R8EUDD4qt+t2r9RBOe1PX\nSwEZq+R"
                    + "/At5iqGJTa8MwCKJV39xn4xWen34PDTwyJQi0vIJDYKIiwTXce1baJDOI"
                    + "\nIBSBL8GuepY6NksfCoiKI7qbM2GbIafxOwiRuTKOaEMIil2RVzb2gqso2TPjwiKi\nQc0mkU+1iIzcUD3VY4MJP5z6K4f"
                    + "/+SUbuVqvedVz/BRt19O2Dau0xxhy7wTkbUuF"
                    + "\nEUH8mbvFep41AkdBXswD92yCopdSt5Q5zeNnsBpSHI8xrsQwMG4G8GMYxwIDAQAB"
                    + "\nMA0GCSqGSIb3DQEBCwUAA4IBAQAzHdoEhyD6EpIzYjGHetfITekYv7yEhyVp4/uR\nnyJJk+jCrQPA0ES4DeSyQ9rQuOc25yCYB"
                    + "+EK+kgXGQNomLZJT1nT0ILGLK9KR4QH\nfLFFXzvfHFMFIp1AvELeAajquNvfeinCWSs4Uu/zFWPltUaP/HTHWndF7Q5pTF2Y"
                    + "\n2uRBgGSkntyhdq5LhPKbABDM9mRH7zSCwJ/0qEyjt5cg02WRegP9ldwZg1knQDFZ"
                    + "\nhQ6l9OpUIbuMitGIRQb3vZwMDsUNE8QQi1CtkU3Lbg7vl5tBXIDPc9SeJmH2NlMj\nYSolkMPImKLtiW/c5m9cUXJp"
                    + "/v4Pn2nNZgwspPDukyQt1+LB\n-----END CERTIFICATE-----\n";


    final X509Certificate certificate = SecurityKeyUtils.parseX509Certificate(cert);
    Key privKey = certificate.getPublicKey();
    assertTrue(privKey != null);
    assertEquals("RSA", privKey.getAlgorithm());
}
 
开发者ID:symphonyoss,项目名称:app-auth-example,代码行数:27,代码来源:SecurityKeyUtilsTest.java

示例4: getKeyFromConfigServer

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
private String getKeyFromConfigServer(RestTemplate keyUriRestTemplate) throws CertificateException {
    // Load available UAA servers
    discoveryClient.getServices();
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    String content = keyUriRestTemplate
        .exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();

    if (StringUtils.isBlank(content)) {
        throw new CertificateException("Received empty certificate from config.");
    }

    InputStream fin = new ByteArrayInputStream(content.getBytes());

    CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
    X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
    PublicKey pk = certificate.getPublicKey();
    return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:19,代码来源:MicroserviceSecurityConfiguration.java

示例5: verifySignature

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Verifies that the given certificate was signed using the private key that corresponds to the 
 * public key of the provided certificate.
 * 
 * @param certificate The X509Certificate which is to be checked
 * @param issuingCertificate The X.509 certificate which holds the public key corresponding to the private 
 * 		  key with which the given certificate should have been signed
 * @return True, if the verification was successful, false otherwise
 */
public static boolean verifySignature(X509Certificate certificate, X509Certificate issuingCertificate) {
	X500Principal subject = certificate.getSubjectX500Principal();
	X500Principal expectedIssuerSubject = certificate.getIssuerX500Principal();
	X500Principal issuerSubject = issuingCertificate.getSubjectX500Principal();
	PublicKey publicKeyForSignature = issuingCertificate.getPublicKey();
	
	try {
		certificate.verify(publicKeyForSignature);
		return true;
	} catch (InvalidKeyException | CertificateException | NoSuchAlgorithmException | 
			 NoSuchProviderException | SignatureException e) {
		getLogger().warn("\n"
					   + "\tSignature verification of certificate having distinguished name \n" 
					   + "\t'" + subject.getName() + "'\n" 
					   + "\twith certificate having distinguished name (the issuer) \n" 
					   + "\t'" + issuerSubject.getName() + "'\n"
					   + "\tfailed. Expected issuer has distinguished name \n"
					   + "\t'" + expectedIssuerSubject.getName() + "' (" + e.getClass().getSimpleName() + ")", e);
	} 
	
	return false;
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:32,代码来源:SecurityUtils.java

示例6: buildChain

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Recursively tries to establish chain from pool of trusted certs.
 *
 * @param certToVerify the cert that needs to be verified.
 * @param chain the chain that's being built.
 * @param certs the pool of trusted certs
 *
 * @return true if successful, false otherwise.
 */
private boolean buildChain(X509Certificate certToVerify,
                    Vector<Certificate> chain,
                    Hashtable<Principal, Vector<Certificate>> certs) {
    Principal issuer = certToVerify.getIssuerDN();
    if (isSelfSigned(certToVerify)) {
        // reached self-signed root cert;
        // no verification needed because it's trusted.
        chain.addElement(certToVerify);
        return true;
    }

    // Get the issuer's certificate(s)
    Vector<Certificate> vec = certs.get(issuer);
    if (vec == null) {
        return false;
    }

    // Try out each certificate in the vector, until we find one
    // whose public key verifies the signature of the certificate
    // in question.
    for (Enumeration<Certificate> issuerCerts = vec.elements();
         issuerCerts.hasMoreElements(); ) {
        X509Certificate issuerCert
            = (X509Certificate)issuerCerts.nextElement();
        PublicKey issuerPubKey = issuerCert.getPublicKey();
        try {
            certToVerify.verify(issuerPubKey);
        } catch (Exception e) {
            continue;
        }
        if (buildChain(issuerCert, chain, certs)) {
            chain.addElement(certToVerify);
            return true;
        }
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:Main.java

示例7: isSelfSigned

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Verifies that this certificate was signed using the private key
 * that corresponds to the specified public key.
 */
private boolean isSelfSigned(X509Certificate cert) throws CertificateException,
        NoSuchAlgorithmException, NoSuchProviderException, BadPaddingException {
    try {
        // Try to verify certificate signature with its own public key
        PublicKey key = cert.getPublicKey();
        cert.verify(key);
        return true;
    } catch (SignatureException sigEx) {
        // Invalid signature --> not self-signed
        return false;
    } catch (InvalidKeyException keyEx) {
        // Invalid key --> not self-signed
        return false;
    }
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:20,代码来源:SelfSignedValidator.java

示例8: getKeyFromAuthorizationServer

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
private String getKeyFromAuthorizationServer(RestTemplate keyUriRestTemplate) throws CertificateException {
    // Load available UAA servers
    discoveryClient.getServices();
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    String content = keyUriRestTemplate
        .exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();

    if (StringUtils.isBlank(content)) {
        throw new CertificateException("Received empty certificate from config.");
    }

    InputStream fin = new ByteArrayInputStream(content.getBytes());

    CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
    X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
    PublicKey pk = certificate.getPublicKey();
    return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
 
开发者ID:xm-online,项目名称:xm-ms-balance,代码行数:19,代码来源:MicroserviceSecurityConfiguration.java

示例9: updateState

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Internal method to manage state information at each iteration
 */
private void updateState(X509Certificate currCert)
    throws CertPathValidatorException
{
    PublicKey cKey = currCert.getPublicKey();
    if (debug != null) {
        debug.println("BasicChecker.updateState issuer: " +
            currCert.getIssuerX500Principal().toString() + "; subject: " +
            currCert.getSubjectX500Principal() + "; serial#: " +
            currCert.getSerialNumber().toString());
    }
    if (PKIX.isDSAPublicKeyWithoutParams(cKey)) {
        // cKey needs to inherit DSA parameters from prev key
        cKey = makeInheritedParamsKey(cKey, prevPubKey);
        if (debug != null) debug.println("BasicChecker.updateState Made " +
                                         "key with inherited params");
    }
    prevPubKey = cKey;
    prevSubject = currCert.getSubjectX500Principal();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:BasicChecker.java

示例10: getPublicKey

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Method getPublicKey
 *
 * @return the publickey
 * @throws XMLSecurityException
 */
public PublicKey getPublicKey() throws XMLSecurityException {
    X509Certificate cert = this.getX509Certificate();

    if (cert != null) {
        return cert.getPublicKey();
    }

    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:XMLX509Certificate.java

示例11: engineLookupAndResolvePublicKey

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Method engineResolvePublicKey
 * @inheritDoc
 * @param element
 * @param BaseURI
 * @param storage
 *
 * @throws KeyResolverException
 */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {

    X509Certificate cert =
        this.engineLookupResolveX509Certificate(element, BaseURI, storage);

    if (cert != null) {
        return cert.getPublicKey();
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:X509CertificateResolver.java

示例12: getKeyFromConfigServer

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
private String getKeyFromConfigServer(TokenKeyService tokenKeyService) throws CertificateException {
    String content = tokenKeyService.getKey();

    if (StringUtils.isBlank(content)) {
        throw new CertificateException("Certificate not found.");
    }

    InputStream fin = new ByteArrayInputStream(content.getBytes());

    CertificateFactory f = CertificateFactory.getInstance(CERTIFICATE);
    X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
    PublicKey pk = certificate.getPublicKey();
    return String.format(PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
 
开发者ID:xm-online,项目名称:xm-ms-config,代码行数:15,代码来源:MicroserviceSecurityConfiguration.java

示例13: engineLookupAndResolvePublicKey

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    X509Certificate cert = this.engineLookupResolveX509Certificate(element, baseURI, storage);

    if (cert != null) {
        return cert.getPublicKey();
    }

    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:X509DigestResolver.java

示例14: getEncryptionKeyForEntity

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public PublicKey getEncryptionKeyForEntity(String entityId) {
    CertificateDto certificateDto = certificatesConfigProxy.getEncryptionCertificate(entityId);
    String base64EncodedCertificateValue = certificateDto.getCertificate();
    final X509Certificate certificate = x509CertificateFactory.createCertificate(base64EncodedCertificateValue);
    KeyStore trustStore = trustStoreForCertificateProvider.getTrustStoreFor(certificateDto.getFederationEntityType());
    validate(certificate, trustStore);

    return certificate.getPublicKey();
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:10,代码来源:ConfigServiceKeyStore.java

示例15: engineLookupAndResolvePublicKey

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Method engineResolvePublicKey
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return null if no {@link PublicKey} could be obtained
 * @throws KeyResolverException
 */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {

    X509Certificate cert =
        this.engineLookupResolveX509Certificate(element, baseURI, storage);

    if (cert != null) {
        return cert.getPublicKey();
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:X509SubjectNameResolver.java


注:本文中的java.security.cert.X509Certificate.getPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。