aboutsummaryrefslogtreecommitdiff
path: root/spss.test/src/testgenerator/TestPKCS12.java
diff options
context:
space:
mode:
authorgregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d>2003-11-11 22:36:36 +0000
committergregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d>2003-11-11 22:36:36 +0000
commit643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc (patch)
tree9e750c9103ad923b291820bc85fcbd669c2e7900 /spss.test/src/testgenerator/TestPKCS12.java
parentbc620256eb9b4dc6a33244b1105e58773358dbe6 (diff)
downloadmoa-id-spss-643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc.tar.gz
moa-id-spss-643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc.tar.bz2
moa-id-spss-643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc.zip
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@51 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'spss.test/src/testgenerator/TestPKCS12.java')
-rw-r--r--spss.test/src/testgenerator/TestPKCS12.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/spss.test/src/testgenerator/TestPKCS12.java b/spss.test/src/testgenerator/TestPKCS12.java
new file mode 100644
index 000000000..97aa8acd0
--- /dev/null
+++ b/spss.test/src/testgenerator/TestPKCS12.java
@@ -0,0 +1,107 @@
+
+package testgenerator;
+import iaik.pkcs.pkcs12.CertificateBag;
+import iaik.pkcs.pkcs12.KeyBag;
+import iaik.pkcs.pkcs12.PKCS12;
+import iaik.security.ecc.ecdsa.ECPrivateKey;
+import iaik.security.ecc.ecdsa.ECPublicKey;
+import iaik.security.ecc.math.ecgroup.ECPoint;
+
+import java.io.FileInputStream;
+
+
+/**
+ * @author stephan
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class TestPKCS12 {
+
+/*
+ public static void main(String[] args) throws Exception {
+
+// String file = "C:/Daten/MOAPhase2/additionalFiles/keys/TestUser.p12";
+// String password = "testuser";
+// String file = "C:\\Certs\\grill(1234).p12";
+// String password = "1234";
+
+ // SL eCard Demo P12 Files
+ String file = "C:\\Daten\\MOAPhase2\\Keys\\sl2002mmdd.ecard.sicher(ego).p12";
+ String password = "ego";
+// String file = "C:\\Daten\\MOAPhase2\\Keys\\sl2002mmdd.ecard.normal(ego).p12";
+// String password = "ego";
+
+ // SL Personalausweis Demo P12 Files
+// String file = "C:\\Daten\\MOAPhase2\\Keys\\sicher-demo(buergerkarte).p12";
+// String password = "buergerkarte";
+// String file = "C:\\Daten\\MOAPhase2\\Keys\\normal().p12";
+// String password = "";
+
+ IAIK.addAsJDK14Provider();
+
+ FileInputStream pkcs12FIS = new FileInputStream(file);
+ PKCS12 pkcs12 = new PKCS12(pkcs12FIS);
+ if (!pkcs12.verify(password.toCharArray()))
+ {
+ System.out.println("could not PKCS12.verify file " + file + " with password " + password);
+ } else
+ {
+ System.out.println("could PKCS12.verify file " + file + " with password " + password);
+ }
+
+ pkcs12.decrypt(password.toCharArray());
+ System.out.println("could PKCS12.decrypt file " + file + " with password " + password);
+
+ KeyBag[] keyBags = pkcs12.getKeyBags();
+ System.out.println("PKCS12.getKeyBags(): " + keyBags.length + " KeyBags found");
+
+ RSAPrivateKey privKey = (RSAPrivateKey) keyBags[0].getPrivateKey();
+ System.out.println("getFriendlyName(): " + keyBags[0].getFriendlyName() );
+
+ X509Certificate[] certBag = CertificateBag.getCertificates(pkcs12.getCertificateBags());
+ System.out.println("PKCS12.getCertificates(): " + certBag.length + " certificates found");
+
+ System.out.println("certBag[0]: " + certBag[0]);
+
+ }
+*/
+
+ public static void main(String[] args) throws Exception {
+ // von Wolfgang Bauer
+ iaik.security.provider.IAIK.addAsProvider();
+ iaik.security.ecc.provider.ECCProvider.addAsProvider();
+
+ final String FILENAME = "sl2002mmdd.ecard.sicher.p12";
+ final char[] PASSWORD = "ego".toCharArray();
+// public final static String FILENAME = "sl2002mmdd.ecard.sicher.p12";
+// public final static char[] PASSWORD = "ego".toCharArray();
+
+ System.out.println("Checking");
+ FileInputStream fis = new FileInputStream(FILENAME);
+ PKCS12 p12 = new PKCS12(fis);
+ p12.decrypt(PASSWORD);
+ CertificateBag[] cb = p12.getCertificateBags();
+
+ KeyBag kb = p12.getKeyBag();
+ ECPrivateKey pk = (ECPrivateKey) kb.getPrivateKey();
+
+ ECPoint p = pk.getParameter().getG();
+ p.multiply(pk.getS());
+
+ ECPoint p2 = ((ECPublicKey)cb[0].getCertificate().getPublicKey()).getW();
+ if (p.equals(p2) ) {
+ System.out.println("Check OK");
+ } else {
+ System.out.println("Nix wars");
+ }
+ cb[0].getCertificate().verify();
+
+ }
+
+
+
+}
+