summaryrefslogtreecommitdiffstats
path: root/vespa-athenz/src/test
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-03-22 12:22:25 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2018-03-22 13:01:10 +0100
commitfacf02d828254ccbf1fd9c2ce0c9d294ac9e693b (patch)
tree84f055bfd3551099e848bf66557dd8befae4eb37 /vespa-athenz/src/test
parentf370e4c8cb2d2e4b8ce4b8fcf6cb6ecda3c024c9 (diff)
Add method for serializing private key to PEM
Rewrite pem deserialization to use BouncyCastle directly instead of using third-party wrapper.
Diffstat (limited to 'vespa-athenz/src/test')
-rw-r--r--vespa-athenz/src/test/java/com/yahoo/vespa/athenz/tls/KeyUtilsTest.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/tls/KeyUtilsTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/tls/KeyUtilsTest.java
index a8730a31838..fca4353d400 100644
--- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/tls/KeyUtilsTest.java
+++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/tls/KeyUtilsTest.java
@@ -3,9 +3,13 @@ package com.yahoo.vespa.athenz.tls;
import org.junit.Test;
import java.security.KeyPair;
+import java.security.PrivateKey;
import java.security.PublicKey;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
/**
* @author bjorncs
@@ -19,4 +23,14 @@ public class KeyUtilsTest {
assertNotNull(publicKey);
}
+ @Test
+ public void can_serialize_deserialize_pem() {
+ KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
+ String pem = KeyUtils.toPem(keyPair.getPrivate());
+ assertThat(pem, containsString("BEGIN PRIVATE KEY"));
+ assertThat(pem, containsString("END PRIVATE KEY"));
+ PrivateKey deserializedKey = KeyUtils.fromPemEncodedPrivateKey(pem);
+ assertEquals(keyPair.getPrivate(), deserializedKey);
+ }
+
} \ No newline at end of file