summaryrefslogtreecommitdiffstats
path: root/core/src/test/java/org/onap/aaf/cadi/JU_AES.java
diff options
context:
space:
mode:
authorsg481n <sg481n@att.com>2017-10-01 21:06:52 +0000
committersg481n <sg481n@att.com>2017-10-01 22:07:06 +0000
commitb5985fb5667b3ee9b6a4a0675fb57f55e7a288b7 (patch)
tree451b6146944e489348a922d552f150ff91e85480 /core/src/test/java/org/onap/aaf/cadi/JU_AES.java
parent7bc6ef245901a83da234c7765d76a7f7eb34540a (diff)
Improve code coverage for aaf cadi modules
Updated few testcases. Issue-ID: AAF-79 Change-Id: If0760b6f3e74d52fa5132224bf1e6f5e3099f0e4 Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'core/src/test/java/org/onap/aaf/cadi/JU_AES.java')
-rw-r--r--core/src/test/java/org/onap/aaf/cadi/JU_AES.java149
1 files changed, 149 insertions, 0 deletions
diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_AES.java b/core/src/test/java/org/onap/aaf/cadi/JU_AES.java
index 11e40a6..4779f09 100644
--- a/core/src/test/java/org/onap/aaf/cadi/JU_AES.java
+++ b/core/src/test/java/org/onap/aaf/cadi/JU_AES.java
@@ -84,5 +84,154 @@ public class JU_AES {
System.out.println(decrypted);
Assert.assertEquals(orig, decrypted);
}
+
+ @Test
+ public void test1() throws Exception {
+ AES aes = new AES();
+ String orig = "I'm a password, really Cool";
+ byte[] passin = orig.getBytes();
+ byte[] encrypted = aes.encrypt(passin);
+ byte[] b64enc = Symm.base64.encode(encrypted);
+ System.out.println(new String(b64enc));
+
+ encrypted = Symm.base64.decode(b64enc);
+ passin = aes.decrypt(encrypted);
+ Assert.assertEquals(orig, new String(passin));
+ }
+
+ @Test
+ public void testInputStream1() throws Exception {
+ AES aes = new AES();
+ String orig = "I'm a password, really cool";
+ ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());
+ CipherInputStream cis = aes.inputStream(bais, true);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Symm.base64.encode(cis, baos);
+ cis.close();
+
+ byte[] b64encrypted;
+ System.out.println(new String(b64encrypted=baos.toByteArray()));
+
+
+ baos.reset();
+ CipherOutputStream cos = aes.outputStream(baos, false);
+ Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);
+ cos.close();
+ Assert.assertEquals(orig, new String(baos.toByteArray()));
+ }
+
+ @Test
+ public void testObtain1() throws Exception {
+ byte[] keygen = Symm.baseCrypt().keygen();
+
+ Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));
+
+ String orig ="Another Password, please cool";
+ String encrypted = symm.enpass(orig);
+ System.out.println(encrypted);
+ String decrypted = symm.depass(encrypted);
+ System.out.println(decrypted);
+ Assert.assertEquals(orig, decrypted);
+ }
+
+
+ @Test
+ public void test2() throws Exception {
+ AES aes = new AES();
+ String orig = "I'm a password, really Nice";
+ byte[] passin = orig.getBytes();
+ byte[] encrypted = aes.encrypt(passin);
+ byte[] b64enc = Symm.base64.encode(encrypted);
+ System.out.println(new String(b64enc));
+
+ encrypted = Symm.base64.decode(b64enc);
+ passin = aes.decrypt(encrypted);
+ Assert.assertEquals(orig, new String(passin));
+ }
+
+ @Test
+ public void testInputStream2() throws Exception {
+ AES aes = new AES();
+ String orig = "I'm a password, really Nice";
+ ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());
+ CipherInputStream cis = aes.inputStream(bais, true);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Symm.base64.encode(cis, baos);
+ cis.close();
+
+ byte[] b64encrypted;
+ System.out.println(new String(b64encrypted=baos.toByteArray()));
+
+
+ baos.reset();
+ CipherOutputStream cos = aes.outputStream(baos, false);
+ Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);
+ cos.close();
+ Assert.assertEquals(orig, new String(baos.toByteArray()));
+ }
+
+ @Test
+ public void testObtain2() throws Exception {
+ byte[] keygen = Symm.baseCrypt().keygen();
+
+ Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));
+
+ String orig ="Another Password, please Nice";
+ String encrypted = symm.enpass(orig);
+ System.out.println(encrypted);
+ String decrypted = symm.depass(encrypted);
+ System.out.println(decrypted);
+ Assert.assertEquals(orig, decrypted);
+ }
+
+
+ @Test
+ public void test3() throws Exception {
+ AES aes = new AES();
+ String orig = "I'm a password, magic";
+ byte[] passin = orig.getBytes();
+ byte[] encrypted = aes.encrypt(passin);
+ byte[] b64enc = Symm.base64.encode(encrypted);
+ System.out.println(new String(b64enc));
+
+ encrypted = Symm.base64.decode(b64enc);
+ passin = aes.decrypt(encrypted);
+ Assert.assertEquals(orig, new String(passin));
+ }
+
+ @Test
+ public void testInputStream3() throws Exception {
+ AES aes = new AES();
+ String orig = "I'm a password, magic";
+ ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());
+ CipherInputStream cis = aes.inputStream(bais, true);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Symm.base64.encode(cis, baos);
+ cis.close();
+
+ byte[] b64encrypted;
+ System.out.println(new String(b64encrypted=baos.toByteArray()));
+
+
+ baos.reset();
+ CipherOutputStream cos = aes.outputStream(baos, false);
+ Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);
+ cos.close();
+ Assert.assertEquals(orig, new String(baos.toByteArray()));
+ }
+
+ @Test
+ public void testObtain3() throws Exception {
+ byte[] keygen = Symm.baseCrypt().keygen();
+
+ Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));
+
+ String orig ="Another Password, magic";
+ String encrypted = symm.enpass(orig);
+ System.out.println(encrypted);
+ String decrypted = symm.depass(encrypted);
+ System.out.println(decrypted);
+ Assert.assertEquals(orig, decrypted);
+ }
}