[Webfunds-commits] java/webfunds/sox Crypto.java

Edwin Woudt edwin@cypherpunks.ai
Tue, 8 Aug 2000 00:02:37 -0400 (AST)


edwin       00/08/08 00:02:37

  Modified:    webfunds/sox Crypto.java
  Log:
  - Proper support for DSA public keys.
  - Support for converting private keys into cryptix keys.

Revision  Changes    Path
1.47      +36 -7     java/webfunds/sox/Crypto.java

Index: Crypto.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Crypto.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- Crypto.java	2000/08/08 03:30:55	1.46
+++ Crypto.java	2000/08/08 04:02:36	1.47
@@ -1,4 +1,4 @@
-/* $Id: Crypto.java,v 1.46 2000/08/08 03:30:55 edwin Exp $
+/* $Id: Crypto.java,v 1.47 2000/08/08 04:02:36 edwin Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -28,6 +28,7 @@
 import java.security.interfaces.RSAPrivateCrtKey;
 import java.security.interfaces.RSAPublicKey;
 import java.security.spec.RSAPublicKeySpec;
+import java.security.spec.RSAPrivateKeySpec;
 import java.util.Date;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
@@ -40,6 +41,7 @@
 import javax.crypto.spec.IvParameterSpec;
 
 import cryptix.openpgp.PGPPublicKey;
+import cryptix.openpgp.PGPSecretKey;
 import cryptix.openpgp.algorithm.PGPRSA;
 
 import cryptix.provider.key.RawSecretKey;
@@ -62,7 +64,7 @@
  *
  * Centralized crypto methods. Currently being overhauled.
  *
- * @version $Revision: 1.46 $
+ * @version $Revision: 1.47 $
  */
 public final class Crypto
 {
@@ -190,6 +192,7 @@
      */
     public static PublicKey getPublicKeyFromCert(Certificate cert)
     {
+        logDebug(cert.toString());
         return toCryptixKey( cert.getPublicKey() );
     }
 
@@ -1108,11 +1111,15 @@
 
         if( pk.getFormat().equals("OpenPGP") ) {
             PGPPublicKey pgppk = (PGPPublicKey)pk;
-            PGPRSA pgprsa = (PGPRSA)pgppk.getSigner();
-            RSAPublicKeySpec rsapubspec = pgprsa.getRSAPublicKeySpec();
-            BigInteger n = rsapubspec.getModulus();
-            BigInteger e = rsapubspec.getPublicExponent();
-            return new RawRSAPublicKey(n, e);   
+            if (pgppk.getSigner() instanceof PGPRSA) {
+                PGPRSA pgprsa = (PGPRSA)pgppk.getSigner();
+                RSAPublicKeySpec rsapubspec = pgprsa.getRSAPublicKeySpec();
+                BigInteger n = rsapubspec.getModulus();
+                BigInteger e = rsapubspec.getPublicExponent();
+                return new RawRSAPublicKey(n, e);   
+            } else {
+                return pk;
+            }
         }
 
         try {
@@ -1127,6 +1134,28 @@
         } catch(IOException e) {
             return null;
         }
+    }
+
+
+    public static PrivateKey toCryptixKey(PrivateKey pk) {
+
+        if( pk.getFormat().equals("OpenPGP") ) {
+
+            PGPSecretKey pgppk = (PGPSecretKey)pk;
+            if (pgppk.getSigner() instanceof PGPRSA) {
+                PGPRSA pgprsa = (PGPRSA)pgppk.getSigner();
+                RSAPrivateKeySpec rsaprivspec = pgprsa.getRSAPrivateKeySpec();
+                BigInteger n = rsaprivspec.getModulus();
+                BigInteger d = rsaprivspec.getPrivateExponent();
+                return new RawRSAPrivateKey(n, d);   
+            } else {
+                return pk;
+            }
+
+        } else {
+            return null;
+        }
+
     }