### Question:
SecurityUtils { public static Key findPrivateKeyByPublic(HttpsConfig config, byte[] publicKey) { if (config.getKeyStore() != null) { try { KeyStore ks = loadKeyStore(config); char[] keyPasswordInChars = config.getKeyPassword(); Key key = null; for (Enumeration<String> e = ks.aliases(); e.hasMoreElements(); ) { String alias = e.nextElement(); Certificate cert = ks.getCertificate(alias); if (Arrays.equals(cert.getPublicKey().getEncoded(), publicKey)) { key = ks.getKey(alias, keyPasswordInChars); if (key != null) { break; } } } return key; } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException | UnrecoverableKeyException e) { apimlLog.log("org.zowe.apiml.common.errorLoadingSecretKey", e.getMessage()); throw new HttpsConfigError("Error loading secret key: " + e.getMessage(), e, HttpsConfigError.ErrorCode.HTTP_CLIENT_INITIALIZATION_FAILED, config); } } return null; }  static String readSecret(HttpsConfig config); static Key loadKey(HttpsConfig config); static Certificate[] loadCertificateChain(HttpsConfig config); static Set<String> loadCertificateChainBase64(HttpsConfig config); static PublicKey loadPublicKey(HttpsConfig config); static Key findPrivateKeyByPublic(HttpsConfig config, byte[] publicKey); static KeyStore loadKeyStore(HttpsConfig config); static URL keyRingUrl(String uri, String trustStore); static String replaceFourSlashes(String storeUri); static KeyPair generateKeyPair(String algorithm, int keySize); static final String SAFKEYRING; }### Answer:
@Test public void testFindPrivateKeyByPublic() { HttpsConfig httpsConfig = httpsConfigBuilder.build(); byte[] publicKey = loadPublicKeyFromFile(); Key secretKey = SecurityUtils.findPrivateKeyByPublic(httpsConfig, publicKey); assertNotNull(secretKey); }
@Test(expected = HttpsConfigError.class) public void testFindPrivateKeyByPublicWithIncorrectKeyPassword() { HttpsConfig httpsConfig = httpsConfigBuilder.keyPassword(WRONG_PARAMETER.toCharArray()).build(); byte[] publicKey = loadPublicKeyFromFile(); Key secretKey = SecurityUtils.findPrivateKeyByPublic(httpsConfig, publicKey); assertNull(secretKey); }