release-request-33b11ddd-d658-45bf-bdb2-acceb024fe39-for-git_oc-release-4042766 snap-temp-L87400000067730042 (snap-temp-branch)

Change-Id: Iff78819927865278af2d845b095ec6ea0312169c
diff --git a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
index 59b715a..63d7b35 100644
--- a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
+++ b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
@@ -642,14 +642,17 @@
             {
                 pbeSpec = (PBEParameterSpec)params;
                 // BEGIN android-added
-                // At this point, k.getParam() == null, so the key hasn't been generated. Recreate
-                // the BCPBEKey with specs from algorithm parameters as to generate the key.
-                k = new BCPBEKey(k.getAlgorithm(), k.getOID(), k.getType(), k.getDigest(),
-                        k.getKeySize(), k.getIvSize(),
-                        new PBEKeySpec(
-                                k.getPassword(), pbeSpec.getSalt(), pbeSpec.getIterationCount(),
-                                k.getKeySize()),
-                        null /* CipherParameters */);
+                // At this point, k.getParam() == null, so the key hasn't been generated.  If
+                // the parameters have non-default values, recreate the BCPBEKey from algorithm
+                // parameters as to generate the key.
+                if ((pbeSpec.getSalt().length != 0) && (pbeSpec.getIterationCount() > 0)) {
+                    k = new BCPBEKey(k.getAlgorithm(), k.getOID(), k.getType(), k.getDigest(),
+                            k.getKeySize(), k.getIvSize(),
+                            new PBEKeySpec(
+                                    k.getPassword(), pbeSpec.getSalt(), pbeSpec.getIterationCount(),
+                                    k.getKeySize()),
+                            null /* CipherParameters */);
+                }
                 // END android-added
                 param = PBE.Util.makePBEParameters(k, params, cipher.getUnderlyingCipher().getAlgorithmName());
             }