-/**\r
- * -\r
- * ============LICENSE_START=======================================================\r
- * Copyright (C) 2019 Nordix Foundation.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * <p>http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * <p>* Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * <p>* SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.dmaap.datarouter.provisioning.utils;\r
-\r
-import java.nio.charset.StandardCharsets;\r
-import java.security.GeneralSecurityException;\r
-import java.util.Base64;\r
-\r
-import javax.crypto.Cipher;\r
-import javax.crypto.SecretKey;\r
-import javax.crypto.SecretKeyFactory;\r
-import javax.crypto.spec.PBEKeySpec;\r
-import javax.crypto.spec.PBEParameterSpec;\r
-import org.onap.dmaap.datarouter.provisioning.ProvRunner;\r
-\r
-/**\r
- * The Processing of a Password. Password can be encrypted and decrypted.\r
- * @author Vikram Singh\r
- * @version $Id: PasswordProcessor.java,v 1.0 2016/12/14 10:16:52 EST\r
- */\r
-public class PasswordProcessor {\r
-\r
- private static final String SECRET_KEY_FACTORY_TYPE = "PBEWithMD5AndDES";\r
- private static final String PASSWORD_ENCRYPTION_STRING =\r
- ProvRunner.getProvProperties().getProperty("org.onap.dmaap.datarouter.provserver.passwordencryption");\r
- private static final char[] PASSWORD = PASSWORD_ENCRYPTION_STRING.toCharArray();\r
- private static final byte[] SALT = {(byte) 0xde, (byte) 0x33, (byte) 0x10,\r
- (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};\r
-\r
- private PasswordProcessor(){\r
- }\r
-\r
- /**\r
- * Encrypt password.\r
- * @param property the Password\r
- * @return Encrypted password.\r
- */\r
- public static String encrypt(String property) throws GeneralSecurityException {\r
- SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(SECRET_KEY_FACTORY_TYPE);\r
- SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));\r
- Cipher pbeCipher = Cipher.getInstance(SECRET_KEY_FACTORY_TYPE);\r
- pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 32));\r
- return Base64.getEncoder().encodeToString(pbeCipher.doFinal(property.getBytes(StandardCharsets.UTF_8)));\r
- }\r
-\r
- /**\r
- * Decrypt password.\r
- * @param property the Password\r
- * @return Decrypt password.\r
- */\r
- public static String decrypt(String property) throws GeneralSecurityException {\r
- SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(SECRET_KEY_FACTORY_TYPE);\r
- SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));\r
- Cipher pbeCipher = Cipher.getInstance(SECRET_KEY_FACTORY_TYPE);\r
- pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 32));\r
- return new String(pbeCipher.doFinal(Base64.getDecoder().decode(property)), StandardCharsets.UTF_8);\r
- }\r
-\r
-}\r