@Override protected Cipher initialValue() { return cipherForAlgorithm(RSA); } };
/** * Creates enc/dec ciphers based on cipher algorithm and secret key. * * @param algorithm - Cipher algorithm * @param secretKey - Secret key */ private CipherPair(String algorithm, SecretKey secretKey) throws InvalidKeyException { this.decCipher = cipherForAlgorithm(algorithm); this.decCipher.init(Cipher.DECRYPT_MODE, secretKey); this.encCipher = cipherForAlgorithm(algorithm); this.encCipher.init(Cipher.ENCRYPT_MODE, secretKey); } }
@Test public void testNotExistingCipherAlgorithm() { Assert.assertNull(MessageEncoderDecoder.cipherForAlgorithm("42")); }
@Test public void testExistingCipherAlgorithm() { Assert.assertNotNull(MessageEncoderDecoder.cipherForAlgorithm("RSA")); }