KeyStoreHelper { public String getPasswordKey(String pwdKeyAlias, char[] pwdKeyPassword) { SecretKey passwordKey; try { passwordKey = (SecretKey) pwdKeyStore.getKey(pwdKeyAlias, pwdKeyPassword); } catch (Exception e) { throw new RuntimeException("Unable to load a key from Key Store. Source " + e.getCause()); } return new String(passwordKey.getEncoded()); } KeyStoreHelper(); byte[] signDataWithPrivateKey(byte[] data); boolean checkDataWithPublicKey(final String publicKeyAlias,
                                          final byte[] data,
                                          final byte[] signature); String getPasswordKey(String pwdKeyAlias, char[] pwdKeyPassword); boolean isSigned(); URL getPvtKeyStoreURL(); char[] getPvtKeyStorePwd(); String getPvtKeyAlias(); char[] getPvtKeyPassword(); URL getPubKeyStoreURL(); char[] getPubKeyStorePwd(); KeyStore getPvtKeyStore(); KeyStore getPubKeyStore();  }
@Test public void testLoadPasswordNoKeystore() { final KeyStoreHelper serverHelper = new KeyStoreHelper(); try { serverHelper.getPasswordKey(null, null); fail(); } catch (final RuntimeException re) { assertTrue(true); } }
@Test public void testLoadPassword() throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException, InvalidKeyException, InvalidKeySpecException { final SecretKey storedSecretKey = storeKeyIntoKeyStoreFile(KEY_PHRASE); final URL serverKeyStoreURL = getClass().getResource(KEYSTORE_JCEKS_RESOURCE_NAME); System.setProperty(KeyStoreConstants.PROP_PWD_KS_URL, serverKeyStoreURL.toExternalForm()); System.setProperty(KeyStoreConstants.PROP_PWD_KS_PWD, KEYSTORE_SERVER_PASSWORD); try { final KeyStoreHelper serverHelper = new KeyStoreHelper(); final String passwordKey = serverHelper.getPasswordKey(KEY_ALIAS, KEY_PASSWORD.toCharArray()); assertEquals(new String(storedSecretKey.getEncoded()), passwordKey); } catch (final RuntimeException re) { re.printStackTrace(); fail(re.getMessage()); } }