Containerization feature of SO
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / bpmn / common / util / CryptoHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.so.bpmn.common.util;
23 import java.io.IOException;
24 import java.security.GeneralSecurityException;
25 import java.util.Properties;
26 import org.onap.so.utils.CryptoUtils;
27
28 import org.onap.so.logger.MsoLogger;
29
30 public class CryptoHandler implements ICryptoHandler {
31         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CryptoHandler.class);
32         private static final String GENERAL_SECURITY_EXCEPTION_PREFIX = "GeneralSecurityException :";
33         private static final String MSO_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
34         private static final String PROPERTY_KEY = "mso.AaiEncrypted.Pwd";
35
36     @Override
37         public String getMsoAaiPassword() {
38         Properties keyProp = new Properties ();
39                 try {
40                         keyProp.load (Thread.currentThread ().getContextClassLoader ().getResourceAsStream ("urn.properties"));
41                         return CryptoUtils.decrypt((String) keyProp.get(PROPERTY_KEY), MSO_KEY);
42                 } catch (GeneralSecurityException | IOException e) {
43                         LOGGER.error(GENERAL_SECURITY_EXCEPTION_PREFIX + e.getMessage(), e);
44                         return null;
45                 }
46         }
47
48
49         @Override
50         public String encryptMsoPassword(String plainMsoPwd) {
51                 try {
52                         return CryptoUtils.encrypt(plainMsoPwd, MSO_KEY);
53                 } catch (GeneralSecurityException e) {
54                         LOGGER.error(GENERAL_SECURITY_EXCEPTION_PREFIX + e.getMessage(), e);
55                         return null;
56                 }
57         }
58
59         @Override
60         public String decryptMsoPassword(String encryptedPwd) {
61                 try {
62                         return CryptoUtils.decrypt(encryptedPwd, MSO_KEY);
63                 } catch (GeneralSecurityException e) {
64                         LOGGER.error(GENERAL_SECURITY_EXCEPTION_PREFIX + e.getMessage(), e);
65                         return null;
66                 }
67         }
68 }