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.test;
\r
25 import java.io.ByteArrayOutputStream;
\r
26 import java.io.File;
\r
27 import java.io.FileInputStream;
\r
29 import org.junit.Test;
\r
30 import org.onap.aaf.cadi.CmdLine;
\r
31 import org.onap.aaf.cadi.Symm;
\r
33 import junit.framework.Assert;
\r
35 import java.io.ByteArrayOutputStream;
\r
36 import java.io.File;
\r
37 import java.io.FileInputStream;
\r
39 import org.junit.AfterClass;
\r
40 import org.junit.Test;
\r
41 import org.onap.aaf.cadi.CmdLine;
\r
42 import org.onap.aaf.cadi.Symm;
\r
44 import junit.framework.Assert;
\r
46 public class JU_Passcode {
\r
48 public void test() throws Exception {
\r
50 long start = System.nanoTime();
\r
51 int gens= 800, en_de=2000;
\r
52 for(int j=0;j<gens;++j) {
\r
53 CmdLine.main(new String[] {"keygen","tempkey"});
\r
56 File fi = new File("tempkey");
\r
57 Assert.assertEquals(2074, fi.length());
\r
58 FileInputStream fis = new FileInputStream(fi);
\r
61 symm = Symm.obtain(fis);
\r
66 String samples[] = {"activevos","ThisIsATestPassword","I have spaces","I have 's, /s and &s and _s"};
\r
67 ByteArrayOutputStream baos;
\r
68 for(int i=0;i<en_de;++i) {
\r
69 String password = samples[i%samples.length];
\r
70 baos = new ByteArrayOutputStream();
\r
71 symm.enpass(password, baos);
\r
72 String pass = baos.toString();
\r
73 byte[] array = baos.toByteArray();
\r
74 for(int k=0;k<array.length;++k) {
\r
76 // for(int k=0;k<pass.length();++k) {
\r
77 // char ch = pass.charAt(k);
\r
78 if(!(Character.isLetter(ch) || Character.isDigit(ch) || ch=='-' || ch=='_' || ch=='=')) {
\r
79 throw new Exception("Yikes, have a bad character..." + ch + '(' + (int)ch + ')');
\r
82 baos = new ByteArrayOutputStream();
\r
83 symm.depass(pass, baos);
\r
84 Assert.assertEquals(password,baos.toString());
\r
85 Assert.assertEquals(password,symm.depass(pass));
\r
88 symm.enpass("activevos", System.out);
\r
89 System.out.println();
\r
91 float ms = (System.nanoTime()-start)/1000000F;
\r
92 System.out.println("Ran " + iterations + " Encrypt/Decrypt cycles + " + gens + " keygens");
\r
94 System.out.println("Total: " + ms + "ms");
\r
95 System.out.println("Avg: " + ms/iterations + "ms");
\r
96 System.out.println("Avg Gen + " + en_de + " Encrypt/Decrypt cycles: " + ms/gens + "ms");
\r
102 public static void tearDown() {
\r