@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."); }
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 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 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); }
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); }
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; }