public KeyPairWrapper(PublicKey publicKey, PrivateKey privateKey) { this(new KeyPair(publicKey, privateKey)); }
/** * Sets the public/private key pair used for this certificate. If unset a key pair will be * generated. */ public Builder keyPair(PublicKey publicKey, PrivateKey privateKey) { return keyPair(new KeyPair(publicKey, privateKey)); }
public KeyPairCredential clone() { final PrivateKey privateKey = keyPair.getPrivate(); final PrivateKey clone = KeyUtil.cloneKey(PrivateKey.class, privateKey); return privateKey == clone ? this : new KeyPairCredential(new KeyPair(keyPair.getPublic(), clone)); }
/** * 从KeyStore中获取私钥公钥 * * @param keyStore {@link KeyStore} * @param password 密码 * @param alias 别名 * @return {@link KeyPair} * @since 4.4.1 */ public static KeyPair getKeyPair(KeyStore keyStore, char[] password, String alias) { PublicKey publicKey; PrivateKey privateKey; try { publicKey = keyStore.getCertificate(alias).getPublicKey(); privateKey = (PrivateKey) keyStore.getKey(alias, password); } catch (Exception e) { throw new CryptoException(e); } return new KeyPair(publicKey, privateKey); }
/** * 从KeyStore中获取私钥公钥 * * @param keyStore {@link KeyStore} * @param password 密码 * @param alias 别名 * @return {@link KeyPair} * @since 4.4.1 */ public static KeyPair getKeyPair(KeyStore keyStore, char[] password, String alias) { PublicKey publicKey; PrivateKey privateKey; try { publicKey = keyStore.getCertificate(alias).getPublicKey(); privateKey = (PrivateKey) keyStore.getKey(alias, password); } catch (Exception e) { throw new CryptoException(e); } return new KeyPair(publicKey, privateKey); }
public KeyPair getKeyPair(String alias, char[] password) { try { synchronized (lock) { if (store == null) { synchronized (lock) { store = KeyStore.getInstance("jks"); store.load(resource.getInputStream(), this.password); } } } RSAPrivateCrtKey key = (RSAPrivateCrtKey) store.getKey(alias, password); RSAPublicKeySpec spec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent()); PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(spec); return new KeyPair(publicKey, key); } catch (Exception e) { throw new IllegalStateException("Cannot load keys from store: " + resource, e); } }
@Override public void setKeyStoreEntry(KeyStore.PrivateKeyEntry entry) { this.key_pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); }
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKeyBytes); crypto.keyPair = new KeyPair(keyFactory.generatePublic(publicKeySpec), keyFactory.generatePrivate(privateKeySpec)); crypto.base64 = base64;
return new KeyPair(publicKey, privateKey);
@Override public void lookupAndInit() { LOG.info("Lookup platform protocols"); Set<String> platformProtocols = PlatformLookup.lookupPlatformProtocols( PlatformLookup.DEFAULT_PROTOCOL_LOOKUP_PACKAGE_NAME); LOG.info("Initializing message handler with {} worker threads", threadPoolSize); handler = new BootstrapMessageHandler( operationsServerListService, Executors.newFixedThreadPool(threadPoolSize), platformProtocols, new KeyPair( bootstrapKeyStoreService.getPublicKey(), bootstrapKeyStoreService.getPrivateKey()), supportUnencryptedConnection); super.lookupAndInit(); }
public static KeyPair loadKey(String pemString, String passwd) throws IOException, GeneralSecurityException { Object key = PEMDecoder.decode(pemString.toCharArray(), passwd); if (key instanceof com.trilead.ssh2.signature.RSAPrivateKey) { com.trilead.ssh2.signature.RSAPrivateKey x = (com.trilead.ssh2.signature.RSAPrivateKey)key; return x.toJCEKeyPair(); } if (key instanceof com.trilead.ssh2.signature.DSAPrivateKey) { com.trilead.ssh2.signature.DSAPrivateKey x = (com.trilead.ssh2.signature.DSAPrivateKey)key; KeyFactory kf = KeyFactory.getInstance("DSA"); return new KeyPair( kf.generatePublic(new DSAPublicKeySpec(x.getY(), x.getP(), x.getQ(), x.getG())), kf.generatePrivate(new DSAPrivateKeySpec(x.getX(), x.getP(), x.getQ(), x.getG()))); } throw new UnsupportedOperationException("Unrecognizable key format: " + key); }
@Test public void validateKeyPairTest() throws Exception { KeyPairGenerator clientKeyGen = KeyPairGenerator.getInstance("RSA"); clientKeyGen.initialize(2048); KeyPair kp = clientKeyGen.genKeyPair(); PublicKey clientPublic = kp.getPublic(); PrivateKey clientPrivate = kp.getPrivate(); Assert.assertTrue(KeyUtil.validateKeyPair(new KeyPair(clientPublic, clientPrivate))); } }
return new KeyPair(publicKey, privateKey); } catch (InvalidKeySpecException e) { throw new RuntimeException(e);
@Override public SingleSignOnSessionFactory get() { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; CredentialSource source = this.credentialSource.get(); try { if (!store.containsAlias(alias)) { throw UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias); } if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { throw UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias); } PasswordCredential credential = source.getCredential(PasswordCredential.class); if (credential == null) { throw UndertowLogger.ROOT_LOGGER.missingCredential(source.toString()); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString()); } KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.get()); return new DefaultSingleSignOnSessionFactory(this.manager.get(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory()))); } catch (GeneralSecurityException | IOException e) { throw new IllegalArgumentException(e); } } }
credential = new PublicKeyCredential(firstCert.getPublicKey()); } else if (credentialType.isAssignableFrom(KeyPairCredential.class)) { credential = new KeyPairCredential(new KeyPair(firstCert.getPublicKey(), privateKey)); } else { return null;
@Override public CipherAuthToken apply(String authValue) { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; try { if (!store.containsAlias(alias)) { throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias); } if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, KeyStore.PrivateKeyEntry.class.getSimpleName()); } PasswordCredential credential = this.keyCredentialSource.get().getCredential(PasswordCredential.class); if (credential == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); KeyPair pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); Cipher cipher = Cipher.getInstance(this.transformation); return new CipherAuthToken(cipher, pair, authValue.getBytes(StandardCharsets.UTF_8)); } catch (GeneralSecurityException | IOException e) { throw new IllegalArgumentException(e); } } }
KeyPair keyPair = new KeyPair(privateKeyEntry.getCertificate().getPublicKey(), privateKeyEntry.getPrivateKey()); Certificate[] certificateChain = privateKeyEntry.getCertificateChain(); if (certificateChain.length != 1) {
return new KeyPair( publicKey, privateKey );
if (privateKey == null) throw reader.missingRequiredElement(xmlVersion.namespace, "private-key-pem"); if (publicKey == null) throw reader.missingRequiredElement(xmlVersion.namespace, "public-key-pem"); return new KeyPair(publicKey, privateKey); } else { throw reader.unexpectedContent();