2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.bpmn.common.util;
26 import java.io.IOException;
27 import java.security.GeneralSecurityException;
28 import java.util.Properties;
29 import org.onap.so.utils.CryptoUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class CryptoHandler implements ICryptoHandler {
34 private static final Logger logger = LoggerFactory.getLogger(CryptoHandler.class);
35 private static final String GENERAL_SECURITY_EXCEPTION_PREFIX = "GeneralSecurityException :";
36 private static final String MSO_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
37 private static final String PROPERTY_KEY = "mso.AaiEncrypted.Pwd";
40 public String getMsoAaiPassword() {
41 Properties keyProp = new Properties();
43 keyProp.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("urn.properties"));
44 return CryptoUtils.decrypt((String) keyProp.get(PROPERTY_KEY), MSO_KEY);
45 } catch (GeneralSecurityException | IOException e) {
46 logger.error(GENERAL_SECURITY_EXCEPTION_PREFIX + e.getMessage(), e);
53 public String encryptMsoPassword(String plainMsoPwd) {
55 return CryptoUtils.encrypt(plainMsoPwd, MSO_KEY);
56 } catch (GeneralSecurityException e) {
57 logger.error(GENERAL_SECURITY_EXCEPTION_PREFIX + e.getMessage(), e);
63 public String decryptMsoPassword(String encryptedPwd) {
65 return CryptoUtils.decrypt(encryptedPwd, MSO_KEY);
66 } catch (GeneralSecurityException e) {
67 logger.error(GENERAL_SECURITY_EXCEPTION_PREFIX + e.getMessage(), e);