aboutsummaryrefslogtreecommitdiff
path: root/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
diff options
context:
space:
mode:
authorAlexander Marsalek <amarsalek@iaik.tugraz.at>2014-06-04 18:50:50 +0200
committerAlexander Marsalek <amarsalek@iaik.tugraz.at>2014-06-04 18:56:07 +0200
commitf81b3716ac27094ab1845668cb38a1fe6a2d5f8c (patch)
tree933cd9ae96e6c7c01b78aea37b904b31419b1b0f /DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
parent31c8bad4214bfee45eef0ca98faf3f6f32fe5b23 (diff)
downloadmoa-id-spss-f81b3716ac27094ab1845668cb38a1fe6a2d5f8c.tar.gz
moa-id-spss-f81b3716ac27094ab1845668cb38a1fe6a2d5f8c.tar.bz2
moa-id-spss-f81b3716ac27094ab1845668cb38a1fe6a2d5f8c.zip
added DocumentService
Diffstat (limited to 'DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java')
-rw-r--r--DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java b/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
new file mode 100644
index 000000000..9ac0862cf
--- /dev/null
+++ b/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
@@ -0,0 +1,63 @@
+package eu.stork.documentservice.tests;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import eu.stork.documentservice.exceptions.EncryptionException;
+import eu.stork.documentservice.utils.EncryptionHelper;
+import eu.stork.documentservice.utils.Utils;
+
+public class EncryptionTests {
+
+ private String pdfLoc = "C:/Temp/temp.pdf";
+ private String certLocation = "C:/Temp/testcert.pem";
+ private static String encKey;
+ private static String encIv;
+
+ @Test
+ //Test encrypting some data
+ public void test1() {
+ try {
+ EncryptionHelper enc = new EncryptionHelper();
+ byte[] data = (Utils.readData(pdfLoc));
+ byte[] encdata = enc.encrypt(data);
+ assertNotNull(encdata);
+ } catch (EncryptionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test encrypting and decrypting some data
+ public void test2() {
+ try {
+ EncryptionHelper enc = new EncryptionHelper();
+ byte[] data = (Utils.readData(pdfLoc));
+ byte[] encdata = enc.encrypt(data);
+ encKey = enc.getKey();
+ encIv = enc.getIv();
+
+ EncryptionHelper enc1 = new EncryptionHelper(encKey, encIv);
+ byte[] decdata = enc1.decrypt(encdata);
+ assertTrue(Arrays.equals(data, decdata));
+ } catch (EncryptionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test encrypting with a certificate
+ public void test3() {
+ try {
+ EncryptionHelper enc = new EncryptionHelper(encKey, encIv);
+ String certString = Utils.readString(certLocation);
+ String secret = enc.encryptWithCert(certString, encKey);
+ assertTrue((secret != null && !secret.isEmpty()));
+ } catch (EncryptionException e) {
+ e.printStackTrace();
+ }
+ }
+}