@Test public void testEncryptPerformance() { final PaillierKeyGenerator keyGenerator = new PaillierKeyGenerator(2048); final PaillierKeyPair keyPair = keyGenerator.generate(); final BigInteger n = keyPair.getPublicKey().getN(); BigInteger encrypted = null; for (int i = 0; i < 20; i++) { final BigInteger x = RandomNumberGenerator.generateRandomInteger(n); encrypted = PaillierCipher.encrypt(keyPair.getPublicKey(), x); } System.out.println("size: " + (encrypted.toByteArray().length)); long timeNs = 0; final int iterations = 1000; final PaillierPublicKey publicKey = keyPair.getPublicKey(); for (int i = 0; i < iterations; i++) { final BigInteger x = RandomNumberGenerator.generateRandomInteger(n); final long start = System.nanoTime(); PaillierCipher.encrypt(publicKey, x); final long end = System.nanoTime(); timeNs += (end - start); } System.out.println("Total time (ms): " + timeNs / (((long)iterations) * 1_000_000.0)); }
public static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message) { final BigInteger n = encryptionKey.getN(); final BigInteger r = RandomNumberGenerator.generateRandomCoprimeInRange(n); return encrypt(encryptionKey, message, r); }
PaillierCipher { public static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message) { final BigInteger n = encryptionKey.getN(); final BigInteger r = RandomNumberGenerator.generateRandomCoprimeInRange(n); return encrypt(encryptionKey, message, r); } }
PaillierCipher { public static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message) { final BigInteger n = encryptionKey.getN(); final BigInteger r = RandomNumberGenerator.generateRandomCoprimeInRange(n); return encrypt(encryptionKey, message, r); }  }
PaillierCipher { public static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message) { final BigInteger n = encryptionKey.getN(); final BigInteger r = RandomNumberGenerator.generateRandomCoprimeInRange(n); return encrypt(encryptionKey, message, r); }  static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message); static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message,
			final BigInteger r); static BigInteger decrypt(final PaillierPrivateKey decryptionKey, final BigInteger ciphertext); }
PaillierCipher { public static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message) { final BigInteger n = encryptionKey.getN(); final BigInteger r = RandomNumberGenerator.generateRandomCoprimeInRange(n); return encrypt(encryptionKey, message, r); }  static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message); static BigInteger encrypt(final PaillierPublicKey encryptionKey, final BigInteger message,
			final BigInteger r); static BigInteger decrypt(final PaillierPrivateKey decryptionKey, final BigInteger ciphertext);  }