@Test(expected = SeedException.class) public void testEncryptWithNoSuchPaddingException(@Mocked final PublicKey publicKey, @Mocked final Cipher cipher) throws Exception { new Expectations() { { Cipher.getInstance("RSA/ECB/PKCS1PADDING"); result = new NoSuchPaddingException("dummy exception"); } }; EncryptionServiceImpl asymetricCrypting = new EncryptionServiceImpl("alias", publicKey, null); final String toCrypt = "text to crypt"; asymetricCrypting.encrypt(toCrypt.getBytes()); }
@Override public byte[] encrypt(byte[] toCrypt) { if (this.publicKey == null) { throw SeedException.createNew(CryptoErrorCode.MISSING_PUBLIC_KEY).put("alias", alias); } return doEncryptionOrDecryption(toCrypt, publicKey, Cipher.ENCRYPT_MODE); }
EncryptionServiceImpl implements EncryptionService { @Override public byte[] encrypt(byte[] toCrypt) { if (this.publicKey == null) { throw SeedException.createNew(CryptoErrorCode.MISSING_PUBLIC_KEY).put("alias", alias); } return doEncryptionOrDecryption(toCrypt, publicKey, Cipher.ENCRYPT_MODE); } }
EncryptionServiceImpl implements EncryptionService { @Override public byte[] encrypt(byte[] toCrypt) { if (this.publicKey == null) { throw SeedException.createNew(CryptoErrorCode.MISSING_PUBLIC_KEY).put("alias", alias); } return doEncryptionOrDecryption(toCrypt, publicKey, Cipher.ENCRYPT_MODE); } EncryptionServiceImpl(String alias, PublicKey publicKey, Key privateKey); }
EncryptionServiceImpl implements EncryptionService { @Override public byte[] encrypt(byte[] toCrypt) { if (this.publicKey == null) { throw SeedException.createNew(CryptoErrorCode.MISSING_PUBLIC_KEY).put("alias", alias); } return doEncryptionOrDecryption(toCrypt, publicKey, Cipher.ENCRYPT_MODE); } EncryptionServiceImpl(String alias, PublicKey publicKey, Key privateKey); @Override byte[] encrypt(byte[] toCrypt); @Override byte[] decrypt(byte[] toDecrypt); }
EncryptionServiceImpl implements EncryptionService { @Override public byte[] encrypt(byte[] toCrypt) { if (this.publicKey == null) { throw SeedException.createNew(CryptoErrorCode.MISSING_PUBLIC_KEY).put("alias", alias); } return doEncryptionOrDecryption(toCrypt, publicKey, Cipher.ENCRYPT_MODE); } EncryptionServiceImpl(String alias, PublicKey publicKey, Key privateKey); @Override byte[] encrypt(byte[] toCrypt); @Override byte[] decrypt(byte[] toDecrypt);  }