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

Ian Grigg iang@cypherpunks.ai
Fri, 5 Jan 2001 14:44:33 -0400 (AST)


iang        01/01/05 14:44:33

  Modified:    webfunds/sox Crypto.java
  Log:
  attempt at equals() method for checking two keys are equal.
  seems to work, but would benefit from review...

Revision  Changes    Path
1.52      +67 -2     java/webfunds/sox/Crypto.java

Index: Crypto.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Crypto.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- Crypto.java	2000/09/04 23:25:11	1.51
+++ Crypto.java	2001/01/05 18:44:33	1.52
@@ -1,4 +1,4 @@
-/* $Id: Crypto.java,v 1.51 2000/09/04 23:25:11 gelderen Exp $
+/* $Id: Crypto.java,v 1.52 2001/01/05 18:44:33 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -60,7 +60,7 @@
  *
  * Centralized crypto methods. Currently being overhauled.
  *
- * @version $Revision: 1.51 $
+ * @version $Revision: 1.52 $
  */
 public final class Crypto
 {
@@ -1083,11 +1083,76 @@
                 return pk;
             }
 
+        } else if( pk.getFormat().equals("Cryptix") ) {
+            RSAPrivateCrtKeyCryptix rsask = (RSAPrivateCrtKeyCryptix)pk;
+            BigInteger n = rsask.getModulus();
+            BigInteger d = rsask.getPrivateExponent();
+            return new RSAPrivateKeyCryptix(n, d);   
+
         } else {
             return null;
         }
     }
 
+    public static boolean equals(PublicKey left, PublicKey right)
+    {
+        if (left == null && right == null)
+            return true ;
+        if (left == null || right == null)
+            return false ;
+
+        RSAPublicKeyImpl ll = (RSAPublicKeyImpl) toCryptixKey(left);
+        RSAPublicKeyImpl rr = (RSAPublicKeyImpl) toCryptixKey(right);
+
+        if (ll == null)               // toCryptixKey() can return null
+            return false ;
+
+        BigInteger left_n = ll.getModulus();
+//System.err.println("\n" + left_n);
+        BigInteger right_n = rr.getModulus();
+//System.err.println("\n" + right_n);
+        if (!left_n.equals(right_n))
+            return false;
+
+        BigInteger left_e = ll.getPublicExponent();
+//System.err.println("\n" + left_e);
+        BigInteger right_e = rr.getPublicExponent();
+//System.err.println("\n" + right_e);
+        if (!left_e.equals(right_e))
+            return false;
+
+        return true ;
+    }
+
+    public static boolean equals(PrivateKey left, PrivateKey right)
+    {
+        if (left == null && right == null)
+            return true ;
+        if (left == null || right == null)
+            return false ;
+
+        RSAPrivateKeyCryptix ll = (RSAPrivateKeyCryptix) toCryptixKey(left);
+        RSAPrivateKeyCryptix rr = (RSAPrivateKeyCryptix) toCryptixKey(right);
+
+        if (ll == null)               // toCryptixKey() can return null
+            return false ;
+
+        BigInteger left_n = ll.getModulus();
+//System.err.println("\n" + left_n);
+        BigInteger right_n = rr.getModulus();
+//System.err.println("\n" + right_n);
+        if (!left_n.equals(right_n))
+            return false;
+
+        BigInteger left_d = ll.getPrivateExponent();
+//System.err.println("\n" + left_d);
+        BigInteger right_d = rr.getPrivateExponent();
+//System.err.println("\n" + right_d);
+        if (!left_d.equals(right_d))
+            return false;
+
+        return true ;
+    }
 
     public static PublicKey toCryptixJCEKey(PublicKey pk) {