X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=appc-config%2Fappc-config-adaptor%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fappc%2Fccadaptor%2FEncryptionTool.java;fp=appc-config%2Fappc-config-adaptor%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fappc%2Fccadaptor%2FEncryptionTool.java;h=a3700ec315c34c63709e9c01e375daf74499eda2;hb=e7752e8d2dd4e4460bf68a7b36548282cc68d0e9;hp=ad09d7fafe6a73b6b64a6b4396f1dc571ebe28b9;hpb=7ed69b1e3f118f0fb19efecf46607c0debb2ea82;p=appc.git diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/EncryptionTool.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/EncryptionTool.java index ad09d7faf..a3700ec31 100644 --- a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/EncryptionTool.java +++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/EncryptionTool.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,9 +23,7 @@ package org.onap.appc.ccadaptor; import java.security.Provider; import java.security.Provider.Service; import java.security.Security; - import javax.crypto.Cipher; - import org.jasypt.contrib.org.apache.commons.codec_1_3.binary.Base64; import org.jasypt.util.text.BasicTextEncryptor; import org.slf4j.Logger; @@ -37,40 +35,40 @@ import org.slf4j.LoggerFactory; */ public class EncryptionTool { + /** + * The prefix we insert onto any data we encrypt so that we can tell if it is encrpyted later and therefore decrypt + * it + */ + @SuppressWarnings("nls") + public static final String ENCRYPTED_VALUE_PREFIX = "enc:"; /** * This lock object is used ONLY if the singleton has not been set up. */ private static final Object lock = new Object(); - /** * The salt is used to initialize the PBE (password Based Encrpytion) algorithm. */ private static final byte[] DEFAULT_SALT = { (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c, (byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99 }; - - /** - * The prefix we insert onto any data we encrypt so that we can tell if it is encrpyted later and therefore decrypt - * it - */ - @SuppressWarnings("nls") - public static final String ENCRYPTED_VALUE_PREFIX = "enc:"; - - /** - * The instance of the encryption utility object - */ - private static EncryptionTool instance = null; - /** * The iteration count used to initialize the PBE algorithm and to generate the key spec */ private static final int ITERATION_COUNT = 20; - /** * The logger for this class. */ private static final Logger LOG = LoggerFactory.getLogger(EncryptionTool.class); - + /** + * The algorithm to encrypt and decrpyt data is "Password (or passphrase) Based Encryption with Message Digest #5 + * and the Data Encryption Standard", i.e., PBEWithMD5AndDES. + */ + @SuppressWarnings("nls") + private static final String SECURITY_ALGORITHM = "PBEWITHMD5AND256BITAES";// "PBEWithMD5AndDES"; + /** + * The instance of the encryption utility object + */ + private static EncryptionTool instance = null; /** * The secret passphrase (PBE) that we use to perform encryption and decryption. The algorithm we are using is a * symmetrical cipher. @@ -80,14 +78,6 @@ public class EncryptionTool { 'b', '"', 'e', 'n', '{', '"', 'l', 'U', 'F', '+', 'E', '\'', 'R', 'T', 'p', '1', 'V', '4', 'l', 'a', '9', 'w', 'v', '5', 'Z', '#', 'i', 'V', '"', 'd', 'l', '!', 'L', 'M', 'g', 'L', 'Q', '{', 'v', 'v', 'K', 'V' }; - - /** - * The algorithm to encrypt and decrpyt data is "Password (or passphrase) Based Encryption with Message Digest #5 - * and the Data Encryption Standard", i.e., PBEWithMD5AndDES. - */ - @SuppressWarnings("nls") - private static final String SECURITY_ALGORITHM = "PBEWITHMD5AND256BITAES";// "PBEWithMD5AndDES"; - /** * The decryption cipher object */ @@ -138,8 +128,8 @@ public class EncryptionTool { /** * Decrypt the provided encrypted text * - * @param cipherText - * THe cipher text to be decrypted. If the ciphertext is not encrypted, then it is returned as is. + * @param cipherText THe cipher text to be decrypted. If the ciphertext is not encrypted, then it is returned as + * is. * @return the clear test of the (possibly) encrypted value. The original value if the string is not encrypted. */ @SuppressWarnings("nls") @@ -159,11 +149,10 @@ public class EncryptionTool { /** * Encrypt the provided clear text * - * @param clearText - * The clear text to be encrypted + * @param clearText The clear text to be encrypted * @return the encrypted text. If the clear text is empty (null or zero length), then an empty string is returned. - * If the clear text is already encrypted, it is not encrypted again and is returned as is. Otherwise, the - * clear text is encrypted and returned. + * If the clear text is already encrypted, it is not encrypted again and is returned as is. Otherwise, the clear + * text is encrypted and returned. */ @SuppressWarnings("nls") public synchronized String encrypt(String clearText) { @@ -177,11 +166,10 @@ public class EncryptionTool { } /** - * Is a value encrypted? A value is considered to be encrypted if it begins with the - * {@linkplain #ENCRYPTED_VALUE_PREFIX encrypted value prefix}. + * Is a value encrypted? A value is considered to be encrypted if it begins with the {@linkplain + * #ENCRYPTED_VALUE_PREFIX encrypted value prefix}. * - * @param value - * the value to check. + * @param value the value to check. * @return true/false; */ private static boolean isEncrypted(final String value) { @@ -192,8 +180,7 @@ public class EncryptionTool { * XORs the input byte array with the secret key, padding 0x0 to the end of the secret key if the input is longer * and returns a byte array the same size as input * - * @param inp - * The byte array to be XORed with secret + * @param inp The byte array to be XORed with secret * @return A byte array the same size as inp or null if input is null. */ private byte[] xorWithSecret(byte[] inp) {