2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapter_utils.tests;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
28 import java.security.GeneralSecurityException;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
33 import org.onap.so.utils.CryptoUtils;
36 * This class implements all test methods of the CryptoUtils features.
40 public class CryptoTest {
42 private static String testKey = "546573746F736973546573746F736973";
45 * This method is called before any test occurs.
46 * It creates a fake tree from scratch
49 public static final void prepare () {
54 * This method implements a test of tree structure, mainly the storage of the leaves structure.
55 * @throws GeneralSecurityException
58 public final void testEncryption () throws GeneralSecurityException {
59 String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
61 final String testData = "This is a test string";
62 final String nonTestData = "This is not the right String";
64 String encodeString = CryptoUtils.encrypt(testData, testKey);
66 assertNotNull(encodeString);
68 assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
69 assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
71 String encode2String = CryptoUtils.encrypt(testData, testKey);
72 assertNotNull(encode2String);
74 assertEquals(CryptoUtils.decrypt(encodeString, testKey),CryptoUtils.decrypt(encode2String, testKey));
76 encodeString = CryptoUtils.encryptCloudConfigPassword(testData);
78 assertEquals(testData, CryptoUtils.decryptCloudConfigPassword(encodeString));
80 System.out.println(CryptoUtils.encrypt("poBpmn:password1$", "aa3871669d893c7fb8abbcda31b88b4f"));