Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit f179169

Browse files
committed
Enable missed decryption test and adjust to new algorithm after #23
1 parent c98ebeb commit f179169

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/main/java/org/sonatype/plexus/components/cipher/PBECipher.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class PBECipher {
5656

5757
protected static final String CIPHER_ALG = "AES/CBC/PKCS5Padding";
5858

59-
protected static final int PBE_ITERATIONS = 1000;
59+
protected static final int PBE_ITERATIONS = 310000;
6060

6161
private static final SecureRandom _secureRandom = new SecureRandom();
6262

@@ -131,9 +131,8 @@ public String decrypt64(final String encryptedText, final String password) throw
131131
private Cipher createCipher(final char[] pwd, byte[] salt, final int mode)
132132
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
133133
InvalidAlgorithmParameterException, InvalidKeySpecException {
134-
MessageDigest _digester = MessageDigest.getInstance(DIGEST_ALG);
135134

136-
KeySpec spec = new PBEKeySpec(pwd, salt, 310000, SPICE_SIZE * 16);
135+
KeySpec spec = new PBEKeySpec(pwd, salt, PBE_ITERATIONS, SPICE_SIZE * 16);
137136
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
138137
byte[] keyAndIv = factory.generateSecret(spec).getEncoded();
139138

src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertFalse;
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.fail;
2223

2324
/**
2425
* Test the Plexus Cipher container
@@ -30,7 +31,7 @@ public class DefaultPlexusCipherTest {
3031

3132
final String str = "my testing phrase";
3233

33-
final String encStr = "LFulS0pAlmMHpDtm+81oPcqctcwpco5p4Fo7640/gqDRifCahXBefG4FxgKcu17v";
34+
final String encStr = "cYrPoOelYU0HGlsn3nERAIyiLVVgnsn/KC5ZqeAPG0beOZCYrFwWwBTp3uyxt/yx";
3435

3536
DefaultPlexusCipher pc;
3637

@@ -138,10 +139,14 @@ public void testEncryptVariableLengths() throws Exception {
138139
}
139140
}
140141

141-
// -------------------------------------------------------------
142-
public void testDecrypt() throws Exception {
143-
String res = pc.decrypt(encStr, passPhrase);
144-
assertEquals("Decryption did not produce desired result", str, res);
142+
@Test
143+
public void testDecrypt() {
144+
try {
145+
String res = pc.decrypt(encStr, passPhrase);
146+
assertEquals("Decryption did not produce desired result", str, res);
147+
} catch (Exception e) {
148+
fail("Decryption failed: " + e.getMessage());
149+
}
145150
}
146151

147152
// -------------------------------------------------------------

0 commit comments

Comments
 (0)