@@ -30,6 +30,7 @@ import javax.annotation.Nullable; | |||
* @since 3.0 | |||
*/ | |||
public final class Encryption { | |||
private static final Pattern ENCRYPTED_PATTERN = Pattern.compile("^\\{([^{^}]*)}(.*)$"); | |||
private static final String BASE64_ALGORITHM = "b64"; | |||
private static final String AES_ECB_ALGORITHM = "aes"; | |||
@@ -39,7 +40,6 @@ public final class Encryption { | |||
private final AesGCMCipher aesGCMCipher; | |||
private final Map<String, Cipher> ciphers; | |||
private static final Pattern ENCRYPTED_PATTERN = Pattern.compile("\\{(.*?)\\}(.*)"); | |||
public Encryption(@Nullable String pathToSecretKey) { | |||
aesECBCipher = new AesECBCipher(pathToSecretKey); |
@@ -91,6 +91,16 @@ public class EncryptionTest { | |||
assertThat(encryption.decrypt("foo")).isEqualTo("foo"); | |||
} | |||
@Test | |||
public void should_notDecryptText_whenBadBraceSyntax(){ | |||
Encryption encryption = new Encryption(null); | |||
assertThat(encryption.decrypt("}xxx{Zm9v")).isEqualTo("}xxx{Zm9v"); | |||
assertThat(encryption.decrypt("}dcd}59LK")).isEqualTo("}dcd}59LK"); | |||
assertThat(encryption.decrypt("}rrrRg6")).isEqualTo("}rrrRg6"); | |||
assertThat(encryption.decrypt("{closedjdk")).isEqualTo("{closedjdk"); | |||
} | |||
private String pathToSecretKey() throws Exception { | |||
URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/aes_secret_key.txt"); | |||
return new File(resource.toURI()).getCanonicalPath(); |