From f73e0b1ff4282aca2e7cb186be7acb12d3ed446b Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 17 Nov 2017 12:08:32 +0100 Subject: Fix for Checkstyle Fix the checkstyle issues reported by the tool Change-Id: Ia330dcf6eead508b0c250d85617ea599c3ce42aa Issue-ID: CLAMP-74 Signed-off-by: Determe, Sebastien (sd378r) --- .../java/org/onap/clamp/clds/util/CryptoUtils.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/onap/clamp/clds/util/CryptoUtils.java b/src/main/java/org/onap/clamp/clds/util/CryptoUtils.java index 8dbdc77d3..efd72515a 100644 --- a/src/main/java/org/onap/clamp/clds/util/CryptoUtils.java +++ b/src/main/java/org/onap/clamp/clds/util/CryptoUtils.java @@ -46,7 +46,8 @@ import org.apache.commons.lang3.ArrayUtils; * */ public final class CryptoUtils { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CryptoUtils.class); + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CryptoUtils.class); // Openssl commands: // Encrypt: echo -n "123456" | openssl aes-128-cbc -e -K // -iv <16 Hex Bytes iv> | xxd -u -g100 @@ -56,12 +57,14 @@ public final class CryptoUtils { // Decrypt: echo -n 'Encrypted string' | xxd -r -ps | openssl aes-128-cbc -d // -K // -iv <16 Bytes IV extracted from Encrypted String> - private static final String ALGORITHM = "AES"; - private static final String ALGORYTHM_DETAILS = ALGORITHM + "/CBC/PKCS5PADDING"; - private static final int BLOCK_SIZE = 128; - private static final String KEY_PARAM = "org.onap.clamp.encryption.aes.key"; - private static SecretKeySpec secretKeySpec = null; - private IvParameterSpec ivspec; + private static final String ALGORITHM = "AES"; + private static final String ALGORYTHM_DETAILS = ALGORITHM + "/CBC/PKCS5PADDING"; + private static final int BLOCK_SIZE = 128; + private static final String KEY_PARAM = "org.onap.clamp.encryption.aes.key"; + private static SecretKeySpec secretKeySpec = null; + private IvParameterSpec ivspec; + + // Static init static { Properties props = new Properties(); try { @@ -76,6 +79,7 @@ public final class CryptoUtils { * Encrypt a value based on the Clamp Encryption Key. * * @param value + * The value to encrypt * @return The encrypted string * @throws GeneralSecurityException * In case of issue with the encryption @@ -84,16 +88,16 @@ public final class CryptoUtils { */ public String encrypt(String value) throws GeneralSecurityException, UnsupportedEncodingException { Cipher cipher = Cipher.getInstance(CryptoUtils.ALGORYTHM_DETAILS, "SunJCE"); - SecureRandom r = SecureRandom.getInstance("SHA1PRNG"); + SecureRandom randomNumber = SecureRandom.getInstance("SHA1PRNG"); byte[] iv = new byte[BLOCK_SIZE / 8]; - r.nextBytes(iv); + randomNumber.nextBytes(iv); ivspec = new IvParameterSpec(iv); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivspec); return Hex.encodeHexString(ArrayUtils.addAll(iv, cipher.doFinal(value.getBytes("UTF-8")))); } /** - * Decrypt a value based on the Clamp Encryption Key + * Decrypt a value based on the Clamp Encryption Key. * * @param message * The encrypted string that must be decrypted using the Clamp -- cgit 1.2.3-korg