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;
27 import java.security.GeneralSecurityException;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.so.utils.CryptoUtils;
33 * This class implements all test methods of the CryptoUtils features.
37 public class CryptoTest {
39 private static String testKey = "546573746F736973546573746F736973";
42 * This method is called before any test occurs. It creates a fake tree from scratch
45 public static final void prepare() {
50 * This method implements a test of tree structure, mainly the storage of the leaves structure.
52 * @throws GeneralSecurityException
55 public final void testEncryption() throws GeneralSecurityException {
56 String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
58 final String testData = "This is a test string";
59 final String nonTestData = "This is not the right String";
61 String encodeString = CryptoUtils.encrypt(testData, testKey);
63 assertNotNull(encodeString);
65 assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
66 assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
68 String encode2String = CryptoUtils.encrypt(testData, testKey);
69 assertNotNull(encode2String);
71 assertEquals(CryptoUtils.decrypt(encodeString, testKey), CryptoUtils.decrypt(encode2String, testKey));
73 encodeString = CryptoUtils.encryptCloudConfigPassword(testData);
75 assertEquals(testData, CryptoUtils.decryptCloudConfigPassword(encodeString));
77 System.out.println(CryptoUtils.encrypt("poBpmn:password1$", "aa3871669d893c7fb8abbcda31b88b4f"));