aboutsummaryrefslogtreecommitdiff
path: root/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
diff options
context:
space:
mode:
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();
+ }
+ }
+}