@Test (expected = NullPointerException.class) public void testEncryptNullMessage () throws Exception { byte[] data = EncryptionUtils.encrypt(generatePublicKey(), null); }
public static byte[] encrypt(PublicKey publicKey, String message) throws Exception { if (publicKey == null) { throw new NullPointerException("public key cannot be empty."); } if (message == null) { throw new NullPointerException("message cannot be null."); } if (message.isEmpty()) { throw new IllegalArgumentException("message cannot be empty."); } Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(message.getBytes()); }
EncryptionUtils { public static byte[] encrypt(PublicKey publicKey, String message) throws Exception { if (publicKey == null) { throw new NullPointerException("public key cannot be empty."); } if (message == null) { throw new NullPointerException("message cannot be null."); } if (message.isEmpty()) { throw new IllegalArgumentException("message cannot be empty."); } Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(message.getBytes()); } }
EncryptionUtils { public static byte[] encrypt(PublicKey publicKey, String message) throws Exception { if (publicKey == null) { throw new NullPointerException("public key cannot be empty."); } if (message == null) { throw new NullPointerException("message cannot be null."); } if (message.isEmpty()) { throw new IllegalArgumentException("message cannot be empty."); } Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(message.getBytes()); } protected  EncryptionUtils(); }
EncryptionUtils { public static byte[] encrypt(PublicKey publicKey, String message) throws Exception { if (publicKey == null) { throw new NullPointerException("public key cannot be empty."); } if (message == null) { throw new NullPointerException("message cannot be null."); } if (message.isEmpty()) { throw new IllegalArgumentException("message cannot be empty."); } Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(message.getBytes()); } protected  EncryptionUtils(); static void init(PublicKey pubKey); static boolean isInitialized(); static byte[] encrypt(PublicKey publicKey, String message); static byte[] encrypt(String message); static byte[] decryptToBytes(PrivateKey privateKey, byte [] encrypted); static String decrypt(PrivateKey privateKey, byte [] encrypted); static PublicKey getPubKeyFromArray(byte[] bytes); static byte[] convertPublicKeyToByteArray(PublicKey publicKey); static KeyPair generateKeyPair(); }
EncryptionUtils { public static byte[] encrypt(PublicKey publicKey, String message) throws Exception { if (publicKey == null) { throw new NullPointerException("public key cannot be empty."); } if (message == null) { throw new NullPointerException("message cannot be null."); } if (message.isEmpty()) { throw new IllegalArgumentException("message cannot be empty."); } Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(message.getBytes()); } protected  EncryptionUtils(); static void init(PublicKey pubKey); static boolean isInitialized(); static byte[] encrypt(PublicKey publicKey, String message); static byte[] encrypt(String message); static byte[] decryptToBytes(PrivateKey privateKey, byte [] encrypted); static String decrypt(PrivateKey privateKey, byte [] encrypted); static PublicKey getPubKeyFromArray(byte[] bytes); static byte[] convertPublicKeyToByteArray(PublicKey publicKey); static KeyPair generateKeyPair();  }