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

Jeroen C. van Gelderen gelderen@cypherpunks.ai
Mon, 31 Jul 2000 14:07:14 -0400 (AST)


gelderen    00/07/31 14:07:14

  Modified:    webfunds/sox Crypto.java
  Log:
  Fix indentation.

Revision  Changes    Path
1.44      +53 -59    java/webfunds/sox/Crypto.java

Index: Crypto.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Crypto.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- Crypto.java	2000/07/31 17:56:18	1.43
+++ Crypto.java	2000/07/31 18:07:14	1.44
@@ -1,4 +1,4 @@
-/* $Id: Crypto.java,v 1.43 2000/07/31 17:56:18 gelderen Exp $
+/* $Id: Crypto.java,v 1.44 2000/07/31 18:07:14 gelderen Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -57,7 +57,7 @@
  *
  * Centralized crypto methods. Currently being overhauled.
  *
- * @version $Revision: 1.43 $
+ * @version $Revision: 1.44 $
  */
 public final class Crypto
 {
@@ -410,70 +410,64 @@
                                     byte[] data, int offset, int len)
         throws KeyException
     {
-      try {
-        // if (sr == null)
-        //    sr = new SecureRandom();
-        
-        java.security.Cipher rsa = 
-            java.security.Cipher.getInstance(pk_alg);
-        pk = toCryptixKey(pk);
-        rsa.initEncrypt(pk);
+        try {
+            java.security.Cipher rsa = 
+                java.security.Cipher.getInstance(pk_alg);
+            pk = toCryptixKey(pk);
+            rsa.initEncrypt(pk);
 
-        byte[] keyData = key.getEncoded();
-        byte[] rsa_pkt = new byte[rsa.getPlaintextBlockSize()];
+            byte[] keyData = key.getEncoded();
+            byte[] rsa_pkt = new byte[rsa.getPlaintextBlockSize()];
         
-        //
-        // Generate the padding
-        //
-        int padlen = rsa_pkt.length - keyData.length - 3;
-        if (padlen < 8)
-            throw new InternalError("No room for padding");
+            //
+            // Generate the padding
+            //
+            int padlen = rsa_pkt.length - keyData.length - 3;
+            if (padlen < 8)
+                throw new InternalError("No room for padding");
         
-        byte[] padding = new byte[padlen];
-        SecureRandom sr = getSecureRandom();
-        sr.nextBytes(padding);
+            byte[] padding = new byte[padlen];
+            SecureRandom sr = getSecureRandom();
+            sr.nextBytes(padding);
         
-        // Find a random non-zero number ...
-        byte rnd = padding[0];
-        for (int i = padlen-1; rnd == 0 && i >= 0; i--)
-        {
-            rnd = padding[i];
-        }
-        // ... with which to replace zero bytes in the padding
-        // (since this padding must be non-zero)
-        for (int i = padlen-1; i >= 0; i--)
-        {
-            if (padding[i] == 0)
-                padding[i] = rnd;
-        }
+            // Find a random non-zero number ...
+            byte rnd = padding[0];
+            for (int i = padlen-1; rnd == 0 && i >= 0; i--)
+                rnd = padding[i];
+
+            // ... with which to replace zero bytes in the padding
+            // (since this padding must be non-zero)
+            for (int i = padlen-1; i >= 0; i--)
+                if (padding[i] == 0)
+                    padding[i] = rnd;
         
-        //
-        // Generate the PKCS#1 packet
-        //
-        rsa_pkt[0] = 0;
-        rsa_pkt[1] = 2;
-        System.arraycopy(padding, 0, rsa_pkt, 2, padlen);
-        rsa_pkt[padlen+2] = 0;
-        System.arraycopy(keyData, 0, rsa_pkt, padlen+3, keyData.length);
+            //
+            // Generate the PKCS#1 packet
+            //
+            rsa_pkt[0] = 0;
+            rsa_pkt[1] = 2;
+            System.arraycopy(padding, 0, rsa_pkt, 2, padlen);
+            rsa_pkt[padlen+2] = 0;
+            System.arraycopy(keyData, 0, rsa_pkt, padlen+3, keyData.length);
         
-        //
-        // Encrypt the data
-        //
-        byte[] encHdr = rsa.crypt(rsa_pkt);
-        byte[] encData = encrypt(key, data, offset, len);
+            //
+            // Encrypt the data
+            //
+            byte[] encHdr = rsa.crypt(rsa_pkt);
+            byte[] encData = encrypt(key, data, offset, len);
         
-        //
-        // Return header + data
-        //
-        byte[] retval = new byte[encData.length + encHdr.length];
-        System.arraycopy(encHdr, 0, retval, 0, encHdr.length);
-        System.arraycopy(encData, 0, retval, encHdr.length, encData.length);
-        return retval;
-
-      } catch (NoSuchAlgorithmException e) {
-          throw new ProviderException("Algorithm (" + pk_alg +
-                                      ") not found (" + e.getMessage()+")");
-      }
+            //
+            // Return header + data
+            //
+            byte[] retval = new byte[encData.length + encHdr.length];
+            System.arraycopy(encHdr, 0, retval, 0, encHdr.length);
+            System.arraycopy(encData, 0, retval, encHdr.length, encData.length);
+            return retval;
+
+        } catch (NoSuchAlgorithmException e) {
+            throw new ProviderException(
+                "Algorithm (" + pk_alg + ") not found (" + e.getMessage()+")");
+        }
     }