PrivateKeyLoader implements EntityLoader { @Override public Object loadSingle(String name, File entitiesFile) { if (!checkPrivateKeyFormat(entitiesFile.getName())) { throw new ConfigLoadException(name + " must be a valid private key extension (.p12)."); } try { return Base64.encodeBase64String(FileUtils.readFileToByteArray(entitiesFile)); } catch (IOException e) { throw new ConfigLoadException("Cannot load private key " + name); } }  @Override void load(Bundle bundle, File rootDir); @Override void load(Bundle bundle, String name, String value); @Override Object loadSingle(String name, File entitiesFile); @Override Map<String, Object> load(File entitiesFile); @Override String getEntityType();  }
@Test void loadSingle() throws IOException { PrivateKeyLoader loader = new PrivateKeyLoader(); createPrivateKeys(new Object[]{"key1", testPrivateKeyContent}); Object certContent = loader.loadSingle("key1", new File(new File(config, "privateKeys"), "key1.p12")); assertNotNull(certContent); assertTrue(certContent instanceof String); assertTrue(Base64.isBase64(certContent.toString())); }
@Test void loadSingleInvalidExtension() throws IOException { PrivateKeyLoader loader = new PrivateKeyLoader(); createPrivateKeys(new Object[]{"key1", testPrivateKeyContent}); assertThrows(ConfigLoadException.class, () -> loader.loadSingle("key1", new File(new File(config, "privateKeys"), "key1.pfx"))); }