@Test public void testPublicKey() { try { KeyPair keyPair = KeyStoreManager.getKeyPair( KeyStoreManagerTest.class.getResource("/" + KEYSTORE) .getPath(), STORE_PASSWORD, KEY_PASSWORD, ALIAS); Assert.assertNotNull("Public Key must not be null", keyPair.getPublic()); Assert.assertNotNull("Private Key must not be null", keyPair.getPrivate()); } catch (Exception e) { e.printStackTrace(); Assert.fail("Shouldn't be here."); } }
public static KeyPair getKeyPair(String keystore, String storePassword, String keyPassword, String alias) throws Exception { KeyStore ks = loadKeyStore(keystore, storePassword); Key key = getKey(keystore, storePassword, keyPassword, alias); PublicKey publicKey = null; PrivateKey privateKey = null; key = ks.getKey(alias, keyPassword.toCharArray()); if (key instanceof PrivateKey) { Certificate cert = ks.getCertificate(alias); publicKey = cert.getPublicKey(); privateKey = (PrivateKey) key; return new KeyPair(publicKey, privateKey); } throw new NoSuchKeyException("Alias '" + alias + "' does not exist in keystore '" + keystore + "'."); }
KeyStoreManager { public static KeyPair getKeyPair(String keystore, String storePassword, String keyPassword, String alias) throws Exception { KeyStore ks = loadKeyStore(keystore, storePassword); Key key = getKey(keystore, storePassword, keyPassword, alias); PublicKey publicKey = null; PrivateKey privateKey = null; key = ks.getKey(alias, keyPassword.toCharArray()); if (key instanceof PrivateKey) { Certificate cert = ks.getCertificate(alias); publicKey = cert.getPublicKey(); privateKey = (PrivateKey) key; return new KeyPair(publicKey, privateKey); } throw new NoSuchKeyException("Alias '" + alias + "' does not exist in keystore '" + keystore + "'."); } }
KeyStoreManager { public static KeyPair getKeyPair(String keystore, String storePassword, String keyPassword, String alias) throws Exception { KeyStore ks = loadKeyStore(keystore, storePassword); Key key = getKey(keystore, storePassword, keyPassword, alias); PublicKey publicKey = null; PrivateKey privateKey = null; key = ks.getKey(alias, keyPassword.toCharArray()); if (key instanceof PrivateKey) { Certificate cert = ks.getCertificate(alias); publicKey = cert.getPublicKey(); privateKey = (PrivateKey) key; return new KeyPair(publicKey, privateKey); } throw new NoSuchKeyException("Alias '" + alias + "' does not exist in keystore '" + keystore + "'."); }  }
KeyStoreManager { public static KeyPair getKeyPair(String keystore, String storePassword, String keyPassword, String alias) throws Exception { KeyStore ks = loadKeyStore(keystore, storePassword); Key key = getKey(keystore, storePassword, keyPassword, alias); PublicKey publicKey = null; PrivateKey privateKey = null; key = ks.getKey(alias, keyPassword.toCharArray()); if (key instanceof PrivateKey) { Certificate cert = ks.getCertificate(alias); publicKey = cert.getPublicKey(); privateKey = (PrivateKey) key; return new KeyPair(publicKey, privateKey); } throw new NoSuchKeyException("Alias '" + alias + "' does not exist in keystore '" + keystore + "'."); }  static KeyPair getKeyPair(String keystore, String storePassword,
	    String keyPassword, String alias); static SecretKey getSecKey(String keystore, String storePassword,
	    String keyPassword, String alias); static KeyInfo createKeyInfo(final XMLSignatureFactory fac,
	    final String certificateFile); static Certificate getCertificate(final String certificateFile); }
KeyStoreManager { public static KeyPair getKeyPair(String keystore, String storePassword, String keyPassword, String alias) throws Exception { KeyStore ks = loadKeyStore(keystore, storePassword); Key key = getKey(keystore, storePassword, keyPassword, alias); PublicKey publicKey = null; PrivateKey privateKey = null; key = ks.getKey(alias, keyPassword.toCharArray()); if (key instanceof PrivateKey) { Certificate cert = ks.getCertificate(alias); publicKey = cert.getPublicKey(); privateKey = (PrivateKey) key; return new KeyPair(publicKey, privateKey); } throw new NoSuchKeyException("Alias '" + alias + "' does not exist in keystore '" + keystore + "'."); }  static KeyPair getKeyPair(String keystore, String storePassword,
	    String keyPassword, String alias); static SecretKey getSecKey(String keystore, String storePassword,
	    String keyPassword, String alias); static KeyInfo createKeyInfo(final XMLSignatureFactory fac,
	    final String certificateFile); static Certificate getCertificate(final String certificateFile);  }