+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.ByteArrayOutputStream;\r
-\r
-import javax.crypto.CipherInputStream;\r
-import javax.crypto.CipherOutputStream;\r
-\r
-import org.junit.Test;\r
-import org.onap.aaf.cadi.AES;\r
-import org.onap.aaf.cadi.Symm;\r
-\r
-import junit.framework.Assert;\r
-\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.File;\r
-import java.io.OutputStream;\r
-\r
-import javax.crypto.CipherInputStream;\r
-import javax.crypto.CipherOutputStream;\r
-\r
-import org.junit.Test;\r
-import org.onap.aaf.cadi.AES;\r
-import org.onap.aaf.cadi.Symm;\r
-\r
-import junit.framework.Assert;\r
-\r
-public class JU_AES {\r
-\r
- @Test\r
- public void test() throws Exception {\r
- AES aes = new AES();\r
- String orig = "I'm a password, really";\r
- byte[] passin = orig.getBytes();\r
- byte[] encrypted = aes.encrypt(passin);\r
- byte[] b64enc = Symm.base64.encode(encrypted);\r
- System.out.println(new String(b64enc));\r
- \r
- encrypted = Symm.base64.decode(b64enc);\r
- passin = aes.decrypt(encrypted);\r
- Assert.assertEquals(orig, new String(passin));\r
- }\r
- \r
- @Test\r
- public void testAESFileStream() throws Exception {\r
- File fi = new File("test/AESKeyFile");\r
- AES aes = new AES(fi);\r
- \r
- String orig = "I'm a password, really";\r
- byte[] passin = orig.getBytes();\r
- byte[] encrypted = aes.encrypt(passin);\r
- byte[] b64enc = Symm.base64.encode(encrypted);\r
- System.out.println(new String(b64enc));\r
- \r
- encrypted = Symm.base64.decode(b64enc);\r
- passin = aes.decrypt(encrypted);\r
- Assert.assertEquals(orig, new String(passin));\r
- \r
- File temp = new File("tempFile");\r
- try {\r
- assertFalse(temp.exists());\r
- aes.save(temp);\r
- assertTrue(temp.exists());\r
- } catch (Exception e) {\r
- } finally {\r
- temp.delete();\r
- } \r
- \r
- }\r
-\r
- @Test\r
- public void testInputStream() throws Exception {\r
- AES aes = new AES();\r
- String orig = "I'm a password, really";\r
- ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());\r
- CipherInputStream cis = aes.inputStream(bais, true);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- Symm.base64.encode(cis, baos);\r
- cis.close();\r
-\r
- byte[] b64encrypted;\r
- System.out.println(new String(b64encrypted=baos.toByteArray()));\r
-\r
- CipherInputStream cis1 = aes.inputStream(bais, false);\r
- ByteArrayOutputStream baos1 = new ByteArrayOutputStream();\r
- Symm.base64.encode(cis1, baos1);\r
- cis.close();\r
-\r
- byte[] b64encrypted1;\r
- System.out.println(new String(b64encrypted1=baos1.toByteArray()));\r
- \r
- baos.reset();\r
- CipherOutputStream cos = aes.outputStream(baos, false);\r
- Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);\r
- cos.close();\r
- Assert.assertEquals(orig, new String(baos.toByteArray()));\r
- \r
- OutputStream stream = aes.outputStream(System.out, true);\r
- assertTrue(stream instanceof CipherOutputStream);\r
-\r
- }\r
-\r
- @Test\r
- public void testObtain() throws Exception {\r
- byte[] keygen = Symm.baseCrypt().keygen();\r
- \r
- Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));\r
- \r
- String orig ="Another Password, please";\r
- String encrypted = symm.enpass(orig);\r
- System.out.println(encrypted);\r
- String decrypted = symm.depass(encrypted);\r
- System.out.println(decrypted);\r
- Assert.assertEquals(orig, decrypted);\r
- }\r
- \r
- @Test\r
- public void test1() throws Exception {\r
- AES aes = new AES();\r
- String orig = "I'm a password, really";\r
- byte[] passin = orig.getBytes();\r
- byte[] encrypted = aes.encrypt(passin);\r
- byte[] b64enc = Symm.base64.encode(encrypted);\r
- System.out.println(new String(b64enc));\r
- \r
- encrypted = Symm.base64.decode(b64enc);\r
- passin = aes.decrypt(encrypted);\r
- Assert.assertEquals(orig, new String(passin));\r
- }\r
- \r
- @Test\r
- public void testAESFileStream1() throws Exception {\r
- File fi = new File("test/AESKeyFile");\r
- AES aes = new AES(fi);\r
- \r
- String orig = "I'm a password, really";\r
- byte[] passin = orig.getBytes();\r
- byte[] encrypted = aes.encrypt(passin);\r
- byte[] b64enc = Symm.base64.encode(encrypted);\r
- System.out.println(new String(b64enc));\r
- \r
- encrypted = Symm.base64.decode(b64enc);\r
- passin = aes.decrypt(encrypted);\r
- Assert.assertEquals(orig, new String(passin));\r
- \r
- File temp = new File("tempFile");\r
- try {\r
- assertFalse(temp.exists());\r
- aes.save(temp);\r
- assertTrue(temp.exists());\r
- } catch (Exception e) {\r
- } finally {\r
- temp.delete();\r
- } \r
- \r
- }\r
-\r
- @Test\r
- public void testInputStream1() throws Exception {\r
- AES aes = new AES();\r
- String orig = "I'm a password, really";\r
- ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());\r
- CipherInputStream cis = aes.inputStream(bais, true);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- Symm.base64.encode(cis, baos);\r
- cis.close();\r
-\r
- byte[] b64encrypted;\r
- System.out.println(new String(b64encrypted=baos.toByteArray()));\r
-\r
- CipherInputStream cis1 = aes.inputStream(bais, false);\r
- ByteArrayOutputStream baos1 = new ByteArrayOutputStream();\r
- Symm.base64.encode(cis1, baos1);\r
- cis.close();\r
-\r
- byte[] b64encrypted1;\r
- System.out.println(new String(b64encrypted1=baos1.toByteArray()));\r
- \r
- baos.reset();\r
- CipherOutputStream cos = aes.outputStream(baos, false);\r
- Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);\r
- cos.close();\r
- Assert.assertEquals(orig, new String(baos.toByteArray()));\r
- \r
- OutputStream stream = aes.outputStream(System.out, true);\r
- assertTrue(stream instanceof CipherOutputStream);\r
-\r
- }\r
-\r
- @Test\r
- public void testObtain1() throws Exception {\r
- byte[] keygen = Symm.baseCrypt().keygen();\r
- \r
- Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));\r
- \r
- String orig ="Another Password, please";\r
- String encrypted = symm.enpass(orig);\r
- System.out.println(encrypted);\r
- String decrypted = symm.depass(encrypted);\r
- System.out.println(decrypted);\r
- Assert.assertEquals(orig, decrypted);\r
- }\r
-}\r