Split PGPEncryptedDataGenerator creation out into a utility method

Split the creation of PGPEncryptedDataGenerator out into a utility
method.  Inline the call to the open() method on the returned generator
rather than storing the generator in a temporary variable.

Suppress deprecation warnings caused by using methods that have been
deprecated in the new version of Bouncycastle that was introduced
recently.  We cannot yet replace the calls with the newer versions
because some Gerrit sites still use the older version of Bouncycastle.

Change-Id: I98f4b7c7bf8ab1ee74eb8bbc86b673d057d98e46
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java b/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java
index 17c9060..40699c8 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java
@@ -173,17 +173,23 @@
     }
   }
 
+  @SuppressWarnings("deprecation")
+  private final PGPEncryptedDataGenerator cpk()
+      throws NoSuchProviderException, PGPException {
+    PGPEncryptedDataGenerator cpk =
+        new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, true, prng, "BC");
+    cpk.addMethod(dest);
+    return cpk;
+  }
+
   private byte[] encrypt(final String name, final Date date,
       final byte[] rawText) throws NoSuchProviderException, PGPException,
       IOException {
     final byte[] zText = compress(name, date, rawText);
-    final PGPEncryptedDataGenerator cpk =
-        new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, true, prng, "BC");
-    cpk.addMethod(dest);
 
     final ByteArrayOutputStream buf = new ByteArrayOutputStream();
     final ArmoredOutputStream aout = new ArmoredOutputStream(buf);
-    final OutputStream cout = cpk.open(aout, zText.length);
+    final OutputStream cout = cpk().open(aout, zText.length);
     cout.write(zText);
     cout.close();
     aout.close();