### Question:
KeyStoreBasedInternalCryptoProvider implements InternalCryptoProvider { @Override public byte[] encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider) throws CryptoException { try { Cipher cipher; if (StringUtils.isBlank(javaSecurityAPIProvider)) { cipher = Cipher.getInstance(algorithm); } else { cipher = Cipher.getInstance(algorithm, javaSecurityAPIProvider); } Certificate certificate = getCertificateFromStore(); if (log.isDebugEnabled()) { log.debug("Certificate used for encrypting : " + certificate); } cipher.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey()); byte[] ciphertext = cipher.doFinal(cleartext); if (log.isDebugEnabled()) { log.debug(String.format("Successfully encrypted data using the algorithm '%s' and the " + "Java Security API provider '%s'", algorithm, javaSecurityAPIProvider)); } return ciphertext; } catch (NoSuchAlgorithmException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException | KeyStoreException | InvalidKeyException | NoSuchProviderException e) { String errorMessage = String.format("An error occurred while encrypting using the algorithm '%s' and the " + "Java Security API provider '%s'", algorithm, javaSecurityAPIProvider); if (log.isDebugEnabled()) { log.debug(errorMessage, e); } throw new CryptoException(errorMessage, e); } } KeyStoreBasedInternalCryptoProvider(KeyStore keyStore, String keyAlias, String keyPassword); @Override byte[] encrypt(byte[] cleartext, String algorithm, String javaSecurityAPIProvider); byte[] decrypt(byte[] ciphertext, String algorithm, String javaSecurityAPIProvider);  }### Answer:
@Test(dataProvider = "encryptionAlgorithms") public void testEncrypting(String algorithm) throws Exception { int plaintextLength = 50; String plaintext = RandomStringUtils.random(plaintextLength); byte[] ciphertext = jksCryptoProvider.encrypt(plaintext.getBytes(CHAR_ENCODING_UTF_8), algorithm, null); Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, privateKey); assertEquals(new String(cipher.doFinal(ciphertext), CHAR_ENCODING_UTF_8), plaintext); }