1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi;
\r
25 import java.io.ByteArrayInputStream;
\r
26 import java.io.ByteArrayOutputStream;
\r
28 import javax.crypto.CipherInputStream;
\r
29 import javax.crypto.CipherOutputStream;
\r
31 import org.junit.Test;
\r
32 import org.onap.aaf.cadi.AES;
\r
33 import org.onap.aaf.cadi.Symm;
\r
35 import junit.framework.Assert;
\r
37 public class JU_AES {
\r
40 public void test() throws Exception {
\r
41 AES aes = new AES();
\r
42 String orig = "I'm a password, really";
\r
43 byte[] passin = orig.getBytes();
\r
44 byte[] encrypted = aes.encrypt(passin);
\r
45 byte[] b64enc = Symm.base64.encode(encrypted);
\r
46 System.out.println(new String(b64enc));
\r
48 encrypted = Symm.base64.decode(b64enc);
\r
49 passin = aes.decrypt(encrypted);
\r
50 Assert.assertEquals(orig, new String(passin));
\r
54 public void testInputStream() throws Exception {
\r
55 AES aes = new AES();
\r
56 String orig = "I'm a password, really";
\r
57 ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());
\r
58 CipherInputStream cis = aes.inputStream(bais, true);
\r
59 ByteArrayOutputStream baos = new ByteArrayOutputStream();
\r
60 Symm.base64.encode(cis, baos);
\r
63 byte[] b64encrypted;
\r
64 System.out.println(new String(b64encrypted=baos.toByteArray()));
\r
68 CipherOutputStream cos = aes.outputStream(baos, false);
\r
69 Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);
\r
71 Assert.assertEquals(orig, new String(baos.toByteArray()));
\r
75 public void testObtain() throws Exception {
\r
76 byte[] keygen = Symm.baseCrypt().keygen();
\r
78 Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));
\r
80 String orig ="Another Password, please";
\r
81 String encrypted = symm.enpass(orig);
\r
82 System.out.println(encrypted);
\r
83 String decrypted = symm.depass(encrypted);
\r
84 System.out.println(decrypted);
\r
85 Assert.assertEquals(orig, decrypted);
\r