diff options
Diffstat (limited to 'cmso-optimizer/src')
3 files changed, 17 insertions, 9 deletions
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java index 6bf0ee8..a638d99 100644 --- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java +++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java @@ -54,7 +54,6 @@ public class PropertiesManagement { private static final String transformation = algorithm + "/" + cipherMode + "/" + paddingScheme; private static final SecureRandom random = new SecureRandom(); - @Autowired Environment env; @@ -100,10 +99,9 @@ public class PropertiesManagement { private static final String encrypt(String key, String value) { try { - - byte[] bytesIV = new byte[16]; - random.nextBytes(bytesIV); - IvParameterSpec iv = new IvParameterSpec(bytesIV); + byte[] bytesIV = new byte[12]; + random.nextBytes(bytesIV); + IvParameterSpec iv = new IvParameterSpec(bytesIV); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance(transformation); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); @@ -119,10 +117,10 @@ public class PropertiesManagement { private static final String decrypt(String key, String encrypted) { try { - byte[] bytesIV = new byte[16]; + byte[] bytesIV = new byte[12]; random.nextBytes(bytesIV); - IvParameterSpec iv = new IvParameterSpec(bytesIV); - SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); + IvParameterSpec iv = new IvParameterSpec(bytesIV); + SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance(transformation); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); byte[] original = cipher.doFinal(Base64.getDecoder().decode(encrypted)); diff --git a/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json b/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json index f260bb1..1a25cf1 100644 --- a/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json +++ b/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json @@ -1,7 +1,7 @@ { "swagger" : "2.0", "info" : { - "version" : "2.3.1-SNAPSHOT", + "version" : "2.3.2-SNAPSHOT", "title" : "cmso-optimizer" }, "basePath" : "/optimizer", diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java index f5adb6f..da7bfbe 100644 --- a/cmso-optimizer/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java +++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java @@ -20,6 +20,9 @@ package org.onap.optf.cmso.utilities; import org.onap.optf.cmso.optimizer.common.PropertiesManagement; +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertAll; +import org.junit.jupiter.api.Test; /** * The Class PropertiesAdmin. @@ -44,5 +47,12 @@ public class PropertiesAdmin { } System.out.println(args[0] + " : " + value); } + @Test + public void testEncryptionDecryption() + { + String encryptedInputData = PropertiesManagement.getEncryptedValue("Hello"); + String decryptedData = PropertiesManagement.getDecryptedValue(encryptedInputData); + assertEquals(decryptedData,"Hello"); + } } |