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


Java PrivateKeyEntry.getCertificate方法代码示例

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


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

示例1: PatchBuilder

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
public PatchBuilder(File outFile, File dexFile, PrivateKeyEntry key,
                    PrintStream verboseStream) {
    try {
        if (null != key) {
            mBuilder = new SignedJarBuilder(
                    new FileOutputStream(outFile, false), key.getPrivateKey(),
                    (X509Certificate) key.getCertificate());
        } else {
            mBuilder = new SignedJarBuilder(
                    new FileOutputStream(outFile, false), null,
                    null);
        }
        mBuilder.writeFile(dexFile, "classes.dex");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:18,代码来源:PatchBuilder.java

示例2: entry2Pair

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
private static KeyPair entry2Pair(Entry entry) {
    PublicKey pub = null;
    PrivateKey priv = null;

    if (entry instanceof PrivateKeyEntry) {
        PrivateKeyEntry pk = (PrivateKeyEntry) entry;
        if (pk.getCertificate() != null) {
            pub = pk.getCertificate().getPublicKey();
        }
        priv = pk.getPrivateKey();
    } else if (entry instanceof TrustedCertificateEntry) {
        TrustedCertificateEntry tc = (TrustedCertificateEntry) entry;
        pub = tc.getTrustedCertificate().getPublicKey();
    } else {
        throw new IllegalArgumentException(
                "Only entry types PrivateKeyEntry and TrustedCertificateEntry are supported.");
    }
    return new KeyPair(pub, priv);
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-encryption-java,代码行数:20,代码来源:KeyStoreMaterialsProvider.java

示例3: setKeystore

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
public JettyKeystoreConvertorBuilder setKeystore(InputStream inputStream, String password, String alias, String type) throws JettyKeystoreException {
    KeyStore keystore = loadKeyStore(inputStream, password, type);

    try {
        PrivateKeyEntry privateKeyEntry = getPrivateKeyEntryOfKeyStore(keystore, password, alias);

        privateKey = privateKeyEntry.getPrivateKey();
        certificate = privateKeyEntry.getCertificate();
    } catch (JettyKeystoreException e) {
        throw new JettyKeystoreException(JettyKeystoreException.ERROR_LOAD_KEYSTORE, "Can not load file (Keystore)", e);
    }

    return this;
}
 
开发者ID:teknux-org,项目名称:jetty-bootstrap,代码行数:15,代码来源:JettyKeystoreConvertorBuilder.java

示例4: generateOCSPResponse

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
private static OCSPResp generateOCSPResponse(PrivateKeyEntry server, PrivateKeyEntry issuer,
        CertificateStatus status) throws CertificateException {
    try {
        X509Certificate serverCertJca = (X509Certificate) server.getCertificate();
        X509Certificate caCertJca = (X509Certificate) issuer.getCertificate();

        X509CertificateHolder caCert = new JcaX509CertificateHolder(caCertJca);

        DigestCalculatorProvider digCalcProv = new BcDigestCalculatorProvider();
        BasicOCSPRespBuilder basicBuilder = new BasicOCSPRespBuilder(
                SubjectPublicKeyInfo.getInstance(caCertJca.getPublicKey().getEncoded()),
                digCalcProv.get(CertificateID.HASH_SHA1));

        CertificateID certId = new CertificateID(digCalcProv.get(CertificateID.HASH_SHA1),
                caCert, serverCertJca.getSerialNumber());

        basicBuilder.addResponse(certId, status);

        BasicOCSPResp resp = basicBuilder.build(
                new JcaContentSignerBuilder("SHA256withRSA").build(issuer.getPrivateKey()),
                null, new Date());

        OCSPRespBuilder builder = new OCSPRespBuilder();
        return builder.build(OCSPRespBuilder.SUCCESSFUL, resp);
    } catch (Exception e) {
        throw new CertificateException("cannot generate OCSP response", e);
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:29,代码来源:TestKeyStore.java

示例5: testPKCS1viaPKCS11

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
@Test
public void testPKCS1viaPKCS11() throws Exception {
	File tmpConfigFile = File.createTempFile("pkcs11-", "conf");
	tmpConfigFile.deleteOnExit();
	PrintWriter configWriter = new PrintWriter(new FileOutputStream(tmpConfigFile), true);
	configWriter.println("name=SmartCard");
	configWriter.println("library=/usr/lib/libbeidpkcs11.so.0");
	configWriter.println("slotListIndex=2");

	SunPKCS11 provider = new SunPKCS11(tmpConfigFile.getAbsolutePath());
	Security.addProvider(provider);
	KeyStore keyStore = KeyStore.getInstance("PKCS11", provider);
	keyStore.load(null, null);
	PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore.getEntry("Authentication", null);
	PrivateKey privateKey = privateKeyEntry.getPrivateKey();
	Signature signature = Signature.getInstance("SHA1withRSA");
	signature.initSign(privateKey);
	byte[] toBeSigned = "hello world".getBytes();
	signature.update(toBeSigned);
	byte[] signatureValue = signature.sign();

	X509Certificate certificate = (X509Certificate) privateKeyEntry.getCertificate();
	RSAPublicKey publicKey = (RSAPublicKey) certificate.getPublicKey();
	BigInteger signatureValueBigInteger = new BigInteger(signatureValue);
	BigInteger messageBigInteger = signatureValueBigInteger.modPow(publicKey.getPublicExponent(),
			publicKey.getModulus());
	LOG.debug("original message: " + new String(Hex.encodeHex(messageBigInteger.toByteArray())));

	// LOG.debug("ASN.1 signature: " + ASN1Dump.dumpAsString(obj)
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:31,代码来源:PKCS11Test.java

示例6: setCertificateFromKeystore

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
public JettyKeystoreConvertorBuilder setCertificateFromKeystore(InputStream inputStream, String password, String alias, String type) throws JettyKeystoreException {
    KeyStore keystore = loadKeyStore(inputStream, password, type);

    try {
        PrivateKeyEntry privateKeyEntry = getPrivateKeyEntryOfKeyStore(keystore, password, alias);

        certificate = privateKeyEntry.getCertificate();
    } catch (JettyKeystoreException e) {
        throw new JettyKeystoreException(JettyKeystoreException.ERROR_LOAD_KEYSTORE, "Can not load file (Keystore)", e);
    }

    return this;
}
 
开发者ID:teknux-org,项目名称:jetty-bootstrap,代码行数:14,代码来源:JettyKeystoreConvertorBuilder.java

示例7: signSamlAssertion

import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
/**
 * Signs and returns the w3c representation of the document containing the SAML assertion.
 * 
 * @param document
 *            w3c document to be signed.
 * @return w3c representation of the signed document.
 * @throws TransformerException
 * @throws NoSuchAlgorithmException
 * @throws InvalidAlgorithmParameterException
 * @throws KeyException
 * @throws MarshalException
 * @throws XMLSignatureException
 */
public Document signSamlAssertion(Document document) throws TransformerException, NoSuchAlgorithmException,
        InvalidAlgorithmParameterException, KeyException, MarshalException, XMLSignatureException {
    if (document != null) {
        PrivateKeyEntry entry = getPrivateKeyEntryFromKeystore();
        PrivateKey privateKey = entry.getPrivateKey();
        X509Certificate certificate = (X509Certificate) entry.getCertificate();
        Element signedElement = signSamlAssertion(document, privateKey, certificate);
        return signedElement.getOwnerDocument();
    }
    return null;
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:25,代码来源:XmlSignatureHelper.java


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