Improve code coverage for aaf cadi modules
[aaf/cadi.git] / core / src / test / java / org / onap / aaf / cadi / JU_AES.java
index 11e40a6..4779f09 100644 (file)
@@ -84,5 +84,154 @@ public class JU_AES {
                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 Cool";\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 testInputStream1() throws Exception {\r
+               AES aes = new AES();\r
+               String orig = "I'm a password, really cool";\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
+               \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
+\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 cool";\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
+       \r
+       @Test\r
+       public void test2() throws Exception {\r
+               AES aes = new AES();\r
+               String orig = "I'm a password, really Nice";\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 testInputStream2() throws Exception {\r
+               AES aes = new AES();\r
+               String orig = "I'm a password, really Nice";\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
+               \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
+\r
+       @Test\r
+       public void testObtain2() throws Exception {\r
+               byte[] keygen = Symm.baseCrypt().keygen();\r
+               \r
+               Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));\r
+               \r
+               String orig ="Another Password, please Nice";\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
+       \r
+       @Test\r
+       public void test3() throws Exception {\r
+               AES aes = new AES();\r
+               String orig = "I'm a password, magic";\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 testInputStream3() throws Exception {\r
+               AES aes = new AES();\r
+               String orig = "I'm a password, magic";\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
+               \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
+\r
+       @Test\r
+       public void testObtain3() throws Exception {\r
+               byte[] keygen = Symm.baseCrypt().keygen();\r
+               \r
+               Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));\r
+               \r
+               String orig ="Another Password, magic";\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
 }\r