From 146284191ee01ea92441fdf3159e9dcd84a6f11a Mon Sep 17 00:00:00 2001 From: "Chou, Joseph" Date: Mon, 18 Mar 2019 13:10:36 -0400 Subject: ONAP password encryption tool sonar fix Update code to fix sonar scan issues Change-Id: I5ccf3d774651bd3d8df908c1e7fe83218016a007 Issue-ID: POLICY-1561 Signed-off-by: Chou, Joseph --- .../policy/common/utils/security/CryptoUtils.java | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java b/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java index ade8b467..ebe0483f 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java +++ b/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java @@ -64,36 +64,14 @@ public class CryptoUtils { private static final String RANDOM_NUMBER_GENERATOR = "SHA1PRNG"; /** - * This method is used as the main entry point when testing. - * + * CryptoUtils - encryption tool constructor. + * @param secretKey + * AES supports 128, 192 or 256-bit long key size, it can be plain text or generated with key generator */ - public static void main(String[] args) { - if (args.length == 3) { - if (args[0].equals("enc")) { - String encryptedValue = encrypt(args[1], args[2]); - logger.info("original value: " + args[1] + " encrypted value: " + encryptedValue); - } else if (args[0].equals("dec")) { - String decryptedValue = decrypt(args[1], args[2]); - logger.info("original value: " + args[1] + " decrypted value: " + decryptedValue); - } else { - logger.info("Unknown request: " + args[0]); - } - } else { - logger.info("Usage : CryptoUtils enc/dec password secretKey"); - logger.info("Example: CryptoUtils enc HelloWorld 1234"); - logger.info("Example: CryptoUtils dec enc:112233 1234"); - } - } - public CryptoUtils(SecretKeySpec secretKeySpec) { this.secretKeySpec = secretKeySpec; } - /** - * CryptoUtils - encryption tool constructor. - * @param secretKey - * AES supports 128, 192 or 256-bit long key size, it can be plain text or generated with key generator - */ public CryptoUtils(String secretKey) { this.secretKeySpec = readSecretKeySpec(secretKey); } @@ -256,4 +234,26 @@ public class CryptoUtils { public static Boolean isEncrypted(String value) { return (value != null && value.startsWith("enc:")); } + + /** + * This method is used as the main entry point when testing. + * + */ + public static void main(String[] args) { + if (args.length == 3) { + if ("enc".equals(args[0])) { + String encryptedValue = encrypt(args[1], args[2]); + logger.info("original value: " + args[1] + " encrypted value: " + encryptedValue); + } else if ("dec".equals(args[0])) { + String decryptedValue = decrypt(args[1], args[2]); + logger.info("original value: " + args[1] + " decrypted value: " + decryptedValue); + } else { + logger.info("Unknown request: " + args[0]); + } + } else { + logger.info("Usage : CryptoUtils enc/dec password secretKey"); + logger.info("Example: CryptoUtils enc HelloWorld 1234"); + logger.info("Example: CryptoUtils dec enc:112233 1234"); + } + } } \ No newline at end of file -- cgit 1.2.3-korg