]> git.datanom.net - libkeystore.git/commitdiff
Initial commit master
authorMichael Rasmussen <mir@datanom.net>
Mon, 4 Dec 2017 23:58:08 +0000 (00:58 +0100)
committerMichael Rasmussen <mir@datanom.net>
Mon, 4 Dec 2017 23:58:08 +0000 (00:58 +0100)
.classpath [new file with mode: 0644]
.gitignore [new file with mode: 0644]
.project [new file with mode: 0644]
src/dk/cbs/archi/libkeystore/KeyStoreInterface.java [new file with mode: 0644]

diff --git a/.classpath b/.classpath
new file mode 100644 (file)
index 0000000..fb50116
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ae3c172
--- /dev/null
@@ -0,0 +1 @@
+/bin/
diff --git a/.project b/.project
new file mode 100644 (file)
index 0000000..91f21ee
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>libkeystore</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/src/dk/cbs/archi/libkeystore/KeyStoreInterface.java b/src/dk/cbs/archi/libkeystore/KeyStoreInterface.java
new file mode 100644 (file)
index 0000000..4cf74f4
--- /dev/null
@@ -0,0 +1,64 @@
+package dk.cbs.archi.libkeystore;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class KeyStoreInterface {
+
+       private String path;
+       private String password;
+       
+       public KeyStoreInterface() {
+               this("", "");
+       }
+
+       public KeyStoreInterface(String path) {
+               this(path, "");
+       }
+
+       public KeyStoreInterface(String path, String password) {
+               this.path = path;
+               this.password = password;
+       }
+       
+       /**
+        * 
+        * @param keyAlias
+        * @param password
+        * @throws Exception KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException
+        */
+       public void getKey(String keyAlias, String password) throws Exception {
+               KeyStore ks = KeyStore.getInstance("PKCS12");
+               FileInputStream fis = new FileInputStream(path);
+               ks.load(fis, this.password.toCharArray());
+               if (ks.containsAlias(keyAlias)) {
+                       //KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
+                       //        ks.getEntry("privateKeyAlias", password);
+                       //PrivateKey myPrivateKey = pkEntry.getPrivateKey();
+                       PrivateKey key = (PrivateKey) ks.getKey(keyAlias, null);
+                       if (key != null)
+                               System.out.println(key.getFormat());
+                       X509Certificate certificate = (X509Certificate) ks.getCertificate(keyAlias);
+                       System.out.println(certificate.toString());
+               }
+       }
+       
+       public static void main(String[] args) {
+               KeyStoreInterface ksi = new KeyStoreInterface("/home/mir/git/libkeystore/keystore.jks", "changeit");
+               try {
+                       ksi.getKey("mykey", "password");
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       }
+
+}
This page took 0.034878 seconds and 5 git commands to generate.