diff --git a/src/main/java/org/sonatype/plexus/components/cipher/PBECipher.java b/src/main/java/org/sonatype/plexus/components/cipher/PBECipher.java index 5f3df00..a3094e1 100644 --- a/src/main/java/org/sonatype/plexus/components/cipher/PBECipher.java +++ b/src/main/java/org/sonatype/plexus/components/cipher/PBECipher.java @@ -28,7 +28,6 @@ Licensed to the Apache Software Foundation (ASF) under one import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; @@ -56,7 +55,7 @@ public class PBECipher { protected static final String CIPHER_ALG = "AES/CBC/PKCS5Padding"; - protected static final int PBE_ITERATIONS = 1000; + protected static final int PBE_ITERATIONS = 310000; private static final SecureRandom _secureRandom = new SecureRandom(); @@ -131,9 +130,8 @@ public String decrypt64(final String encryptedText, final String password) throw private Cipher createCipher(final char[] pwd, byte[] salt, final int mode) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, InvalidKeySpecException { - MessageDigest _digester = MessageDigest.getInstance(DIGEST_ALG); - KeySpec spec = new PBEKeySpec(pwd, salt, 310000, SPICE_SIZE * 16); + KeySpec spec = new PBEKeySpec(pwd, salt, PBE_ITERATIONS, SPICE_SIZE * 16); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); byte[] keyAndIv = factory.generateSecret(spec).getEncoded(); diff --git a/src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java b/src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java index cf403aa..669ac23 100644 --- a/src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java +++ b/src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Test the Plexus Cipher container @@ -30,7 +31,7 @@ public class DefaultPlexusCipherTest { final String str = "my testing phrase"; - final String encStr = "LFulS0pAlmMHpDtm+81oPcqctcwpco5p4Fo7640/gqDRifCahXBefG4FxgKcu17v"; + final String encStr = "cYrPoOelYU0HGlsn3nERAIyiLVVgnsn/KC5ZqeAPG0beOZCYrFwWwBTp3uyxt/yx"; DefaultPlexusCipher pc; @@ -138,10 +139,14 @@ public void testEncryptVariableLengths() throws Exception { } } - // ------------------------------------------------------------- - public void testDecrypt() throws Exception { - String res = pc.decrypt(encStr, passPhrase); - assertEquals("Decryption did not produce desired result", str, res); + @Test + public void testDecrypt() { + try { + String res = pc.decrypt(encStr, passPhrase); + assertEquals("Decryption did not produce desired result", str, res); + } catch (Exception e) { + fail("Decryption failed: " + e.getMessage()); + } } // -------------------------------------------------------------