本文整理汇总了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();
}
}
示例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);
}
}
示例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);
}
}
示例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));
}
示例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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
}
示例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;
}