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


Java PrivateKeyEntry类代码示例

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


PrivateKeyEntry类属于java.security.KeyStore包,在下文中一共展示了PrivateKeyEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: addSelfSignedCertificate

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
public void addSelfSignedCertificate(String certificateAlias, String dn, String password) {
	try {
		KeyPair keys = generateKeyPair();

		Calendar start = Calendar.getInstance();
		Calendar expiry = Calendar.getInstance();
		expiry.add(Calendar.YEAR, 1);
		X500Name name = new X500Name(dn);
		X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(name, BigInteger.ONE,
				start.getTime(), expiry.getTime(), name, SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded()));
		ContentSigner signer = new JcaContentSignerBuilder("SHA1WithRSA").setProvider(new BouncyCastleProvider()).build(keys.getPrivate());
		X509CertificateHolder holder = certificateBuilder.build(signer);
		Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);

		Entry entry = new PrivateKeyEntry(keys.getPrivate(), new Certificate[]{ cert });
		keystore.setEntry(certificateAlias, entry, new PasswordProtection(password.toCharArray()));
	} catch (GeneralSecurityException | OperatorCreationException ex) {
		throw new RuntimeException("Unable to generate self-signed certificate", ex);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:21,代码来源:XTFKeyStore.java

示例3: addPrivateKey

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
/**
 * Asymmetric cryptography - only the private key from generated pair is used.
 * Pre-condition: #certificateAlias refers to existing certificate
 *
 * @throws {@link NullPointerException} when #certificateAlias is @code{null}
 */
public void addPrivateKey(String keyAlias, String certificateAlias, String password) {
	keyAlias = String.format("%s (%s)", keyAlias, certificateAlias);

	try {
		Certificate[] certChain = keystore.getCertificateChain(certificateAlias);
		if (certChain == null) {
			LoggerFactory.getLogger(getClass()).warn("Could not find certificate");
			certChain = new Certificate[0];
		}
		Entry entry = new PrivateKeyEntry(generateKeyPair().getPrivate(), certChain);
		ProtectionParameter protParam = new KeyStore.PasswordProtection(password.toCharArray());
		keystore.setEntry(keyAlias, entry, protParam);
	} catch (KeyStoreException | NoSuchAlgorithmException ex) {
		throw new RuntimeException("Unable to add new private key", ex);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:23,代码来源:XTFKeyStore.java

示例4: engineGetEntry

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
/** {@inheritDoc} */
  @Override
  public KeyStore.Entry engineGetEntry(final String alias,
  		                             final ProtectionParameter protParam) {
  	if (protParam instanceof KeyStore.PasswordProtection) {
   	final PasswordCallback pwc = new CachePasswordCallback(((KeyStore.PasswordProtection)protParam).getPassword());
	this.cryptoCard.setPasswordCallback(pwc);
  	}
  	if (!engineContainsAlias(alias)) {
  		return null;
  	}
  	final PrivateKey key = (PrivateKey) engineGetKey(
	alias,
	null // Le pasamos null porque ya hemos establecido el PasswordCallback o el CallbackHander antes
);
  	return new PrivateKeyEntry(key, engineGetCertificateChain(alias));
  }
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:18,代码来源:CeresKeyStoreImpl.java

示例5: newNettyServerContext

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
private static SslContext newNettyServerContext(
        io.netty.handler.ssl.SslProvider sslProvider, boolean useAlpn) {
    try {
        PrivateKeyEntry server = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
        SslContextBuilder ctx =
                SslContextBuilder
                        .forServer(server.getPrivateKey(),
                                (X509Certificate[]) server.getCertificateChain())
                        .sslProvider(sslProvider);
        if (useAlpn) {
            ctx.applicationProtocolConfig(OpenJdkEngineFactoryConfig.NETTY_ALPN_CONFIG);
        }
        return ctx.build();
    } catch (SSLException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:18,代码来源:OpenJdkEngineFactory.java

示例6: testGetEntry

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
@Test
public void testGetEntry() throws Exception {
	Security.addProvider(new BeIDProvider());

	final KeyStore keyStore = KeyStore.getInstance("BeID");
	keyStore.load(null);
	PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore.getEntry("Authentication", null);
	assertNotNull(privateKeyEntry);
	assertTrue(privateKeyEntry.getPrivateKey() instanceof BeIDPrivateKey);

	TrustedCertificateEntry caEntry = (TrustedCertificateEntry) keyStore.getEntry("CA", null);
	assertNotNull(caEntry);
	LOGGER.debug("CA entry: {}", ((X509Certificate) caEntry.getTrustedCertificate()).getSubjectX500Principal());

	TrustedCertificateEntry rootEntry = (TrustedCertificateEntry) keyStore.getEntry("Root", null);
	assertNotNull(rootEntry);
	LOGGER.debug("root entry: {}", ((X509Certificate) rootEntry.getTrustedCertificate()).getSubjectX500Principal());
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:19,代码来源:JCATest.java

示例7: engineGetEntry

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
@Override
public Entry engineGetEntry(String alias, ProtectionParameter protParam)
		throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
	LOGGER.debug("engineGetEntry: {}", alias);
	if ("Authentication".equals(alias) || "Signature".equals(alias)) {
		PrivateKey privateKey = (PrivateKey) engineGetKey(alias, null);
		Certificate[] chain = engineGetCertificateChain(alias);
		PrivateKeyEntry privateKeyEntry = new PrivateKeyEntry(privateKey, chain);
		return privateKeyEntry;
	}
	if ("CA".equals(alias) || "Root".equals(alias) || "RRN".equals(alias)) {
		Certificate certificate = engineGetCertificate(alias);
		TrustedCertificateEntry trustedCertificateEntry = new TrustedCertificateEntry(certificate);
		return trustedCertificateEntry;
	}
	return super.engineGetEntry(alias, protParam);
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:18,代码来源:BeIDKeyStore.java

示例8: test_X509KeyManager_alias

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
private void test_X509KeyManager_alias(X509KeyManager km, String alias, String keyType) {
    if (alias == null) {
        assertNull(km.getCertificateChain(alias));
        assertNull(km.getPrivateKey(alias));
        return;
    }

    X509Certificate[] certificateChain = km.getCertificateChain(alias);
    PrivateKey privateKey = km.getPrivateKey(alias);

    if (keyType == null) {
        keyType = privateKey.getAlgorithm();
    } else {
        assertEquals(keyType, certificateChain[0].getPublicKey().getAlgorithm());
        assertEquals(keyType, privateKey.getAlgorithm());
    }

    PrivateKeyEntry privateKeyEntry
            = TestKeyStore.privateKey(TEST_KEY_STORE.keyStore,
                                      TEST_KEY_STORE.storePassword,
                                      keyType);
    assertEquals(Arrays.asList(privateKeyEntry.getCertificateChain()),
                 Arrays.asList(certificateChain));
    assertEquals(privateKeyEntry.getPrivateKey(), privateKey);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:KeyManagerFactoryTest.java

示例9: isCertificateExists

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
public boolean isCertificateExists(String paramString)
{
  if (this.context == null)
    return false;
  try
  {
    KeyStore.PrivateKeyEntry localPrivateKeyEntry = getPrivateKeyEntry(paramString);
    int i = 0;
    if (localPrivateKeyEntry != null)
      i = 1;
    return i;
  }
  catch (Exception localException)
  {
    WLUtils.error("Failed to determine the existence of certificate for device authentication with " + localException.getMessage(), localException);
  }
  return false;
}
 
开发者ID:zhangjianying,项目名称:12306-android-Decompile,代码行数:19,代码来源:WLDeviceAuthManager.java

示例10: signDeviceAuth

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
public String signDeviceAuth(String paramString1, String paramString2, boolean paramBoolean)
  throws Exception
{
  if ((paramBoolean) && (isCertificateExists(paramString2)))
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("alg", "RS256");
    KeyStore.PrivateKeyEntry localPrivateKeyEntry = getPrivateKeyEntry(paramString2);
    localJSONObject.put("x5c", Base64.encodeUrlSafe(localPrivateKeyEntry.getCertificate().getEncoded(), "UTF-8"));
    String str1 = localJSONObject.toString();
    String str2 = Base64.encodeUrlSafe(str1.getBytes(), "UTF-8") + "." + Base64.encodeUrlSafe(paramString1.getBytes(), "UTF-8");
    String str3 = Base64.encodeUrlSafe(signData(str2, localPrivateKeyEntry.getPrivateKey()), "UTF-8");
    return str2 + "." + str3;
  }
  return paramString1;
}
 
开发者ID:zhangjianying,项目名称:12306-android-Decompile,代码行数:17,代码来源:WLDeviceAuthManager.java

示例11: 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

示例12: testBuildClientWithCertificateAndPasswordProtectedKey

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
@Test
public void testBuildClientWithCertificateAndPasswordProtectedKey() throws Exception {
    // We're happy here as long as nothing throws an exception
    try (final InputStream p12InputStream = this.getClass().getResourceAsStream(SINGLE_TOPIC_CLIENT_KEYSTORE_FILENAME)) {
        final PrivateKeyEntry privateKeyEntry =
                P12Util.getFirstPrivateKeyEntryFromP12InputStream(p12InputStream, KEYSTORE_PASSWORD);

        final ApnsClient client = new ApnsClientBuilder()
                .setApnsServer(ApnsClientBuilder.PRODUCTION_APNS_HOST)
                .setEventLoopGroup(EVENT_LOOP_GROUP)
                .setClientCredentials((X509Certificate) privateKeyEntry.getCertificate(), privateKeyEntry.getPrivateKey(), KEYSTORE_PASSWORD)
                .build();

        client.close().await();
    }
}
 
开发者ID:relayrides,项目名称:pushy,代码行数:17,代码来源:ApnsClientBuilderTest.java

示例13: testBuildClientWithCertificateAndUnprotectedKey

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
@Test
public void testBuildClientWithCertificateAndUnprotectedKey() throws Exception {
    // We DO need a password to unlock the keystore, but the key itself should be unprotected
    try (final InputStream p12InputStream = this.getClass().getResourceAsStream(SINGLE_TOPIC_CLIENT_KEYSTORE_UNPROTECTED_FILENAME)) {

        final PrivateKeyEntry privateKeyEntry =
                P12Util.getFirstPrivateKeyEntryFromP12InputStream(p12InputStream, KEYSTORE_PASSWORD);

        final ApnsClient client = new ApnsClientBuilder()
                .setApnsServer(ApnsClientBuilder.PRODUCTION_APNS_HOST)
                .setEventLoopGroup(EVENT_LOOP_GROUP)
                .setClientCredentials((X509Certificate) privateKeyEntry.getCertificate(), privateKeyEntry.getPrivateKey(), null)
                .build();

        client.close().await();
    }
}
 
开发者ID:relayrides,项目名称:pushy,代码行数:18,代码来源:ApnsClientBuilderTest.java

示例14: testBuildWithClientCredentialsAndSigningCertificate

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testBuildWithClientCredentialsAndSigningCertificate() throws Exception {
    try (final InputStream p12InputStream = this.getClass().getResourceAsStream(SINGLE_TOPIC_CLIENT_KEYSTORE_UNPROTECTED_FILENAME)) {

        final PrivateKeyEntry privateKeyEntry =
                P12Util.getFirstPrivateKeyEntryFromP12InputStream(p12InputStream, KEYSTORE_PASSWORD);

        try (final InputStream p8InputStream = this.getClass().getResourceAsStream(SIGNING_KEY_FILENAME)) {

            final ApnsSigningKey signingKey = ApnsSigningKey.loadFromInputStream(p8InputStream, "TEAM_ID", "KEY_ID");

            new ApnsClientBuilder()
                    .setEventLoopGroup(EVENT_LOOP_GROUP)
                    .setClientCredentials((X509Certificate) privateKeyEntry.getCertificate(), privateKeyEntry.getPrivateKey(), null)
                    .setSigningKey(signingKey)
                    .build();
        }
    }
}
 
开发者ID:relayrides,项目名称:pushy,代码行数:20,代码来源:ApnsClientBuilderTest.java

示例15: storeOwnAsymmetric

import java.security.KeyStore.PrivateKeyEntry; //导入依赖的package包/类
public static boolean storeOwnAsymmetric(KeyPair pair)
	{
		X509Certificate cert = generateSelfSignedCertificate(pair);
		KeyStore.PrivateKeyEntry privEntry = new PrivateKeyEntry(pair.getPrivate(), new java.security.cert.Certificate[] {cert});
		
		try {
//			KeyStore ks = load(c);
			ks.setEntry("ownPrivate", privEntry, pp);
			ks.setCertificateEntry("ownCert", cert);
//			closeStore();
			return true;
		} catch (KeyStoreException e) {
			e.printStackTrace();
		}
		
		return false;
	}
 
开发者ID:To0x,项目名称:dCache-Cloud,代码行数:18,代码来源:KeyStoreHelper.java


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