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

Enable missed decryption test and adjust to new algorithm after #23 #34

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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());
}
}

// -------------------------------------------------------------
Expand Down