### Question:
BasicEncryptionTransformFactory extends
        EncryptionTransformFactory<BasicEncryptionOutputTransform, BasicEncryptionInputTransform> { public void setMasterEncryptionKey(KeyPair pair) { if (!(pair.getPublic() instanceof RSAPublicKey)) { throw new IllegalArgumentException( "Only RSA KeyPairs are allowed, not " + pair.getPublic().getAlgorithm()); } checkKeyLength(pair); this.masterEncryptionKey = pair; try { this.masterEncryptionKeyFingerprint = KeyUtils .getRsaPublicKeyFingerprint((RSAPublicKey) pair.getPublic(), provider); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Error adding master key", e); } addMasterDecryptionKey(pair); } BasicEncryptionTransformFactory();  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys);  BasicEncryptionTransformFactory(KeyPair masterEncryptionKey, 
            Set<KeyPair> masterDecryptionKeys, Provider provider); void setMasterEncryptionKey(KeyPair pair); void addMasterDecryptionKey(KeyPair pair); @Override Map<String, String> rekey(Map<String, String> metadata); @Override BasicEncryptionOutputTransform getOutputTransform(
            OutputStream streamToEncodeTo, Map<String, String> metadataToEncode); @Override BasicEncryptionOutputTransform getOutputTransform(
            InputStream streamToEncode, Map<String, String> metadataToEncode); @Override BasicEncryptionInputTransform getInputTransform(
            String transformConfig, InputStream streamToDecode,
            Map<String, String> metadata); public KeyPair masterEncryptionKey; }### Answer:
@Test public void testRejectSmallKey() throws Exception { BasicEncryptionTransformFactory factory = new BasicEncryptionTransformFactory(); factory.setCryptoProvider(provider); KeyPair smallKey = null; try { smallKey = KeyUtils.rsaKeyPairFromBase64( keyprops.getProperty("smallkey.public"), keyprops.getProperty("smallkey.private")); } catch (Exception e) { logger.info("Key was properly rejected by JVM: " + e); return; } try { factory.setMasterEncryptionKey(smallKey); } catch (Exception e) { logger.info("Key was properly rejected by factory: " + e); return; } fail("RSA key < 1024 bits should have been rejected by factory"); }
@Test public void testSetMasterEncryptionKey() throws Exception { BasicEncryptionTransformFactory factory = new BasicEncryptionTransformFactory(); factory.setCryptoProvider(provider); factory.setMasterEncryptionKey(masterKey); }
@Test public void testRejectNonRsaMasterKey() throws Exception { KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("DSA"); keyGenerator.initialize(512, new SecureRandom()); KeyPair myKeyPair = keyGenerator.generateKeyPair(); BasicEncryptionTransformFactory factory = new BasicEncryptionTransformFactory(); factory.setCryptoProvider(provider); try { factory.setMasterEncryptionKey(myKeyPair); } catch (Exception e) { logger.info("DSA key was properly rejected by factory: " + e); return; } fail("DSA keys should not be allowed."); }