[Webfunds-commits] java/webfunds/sox Crypto.java
Jeroen C. van Gelderen
gelderen@cypherpunks.ai
Mon, 31 Jul 2000 13:56:19 -0400 (AST)
gelderen 00/07/31 13:56:19
Modified: webfunds/sox Crypto.java
Log:
Checkpoint: Use JCE for symmetric DEcryption.
Revision Changes Path
1.43 +18 -24 java/webfunds/sox/Crypto.java
Index: Crypto.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Crypto.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- Crypto.java 2000/07/31 17:22:32 1.42
+++ Crypto.java 2000/07/31 17:56:18 1.43
@@ -1,4 +1,4 @@
-/* $Id: Crypto.java,v 1.42 2000/07/31 17:22:32 gelderen Exp $
+/* $Id: Crypto.java,v 1.43 2000/07/31 17:56:18 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.42 $
+ * @version $Revision: 1.43 $
*/
public final class Crypto
{
@@ -281,15 +281,15 @@
{
logDebug("encrypt() called");
try {
- Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS#5",
- "CryptixCrypto");
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = new GZIPOutputStream(baos);
gzos.write(data, offset, len);
gzos.finish();
byte[] zipped = baos.toByteArray();
+ Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS#5",
+ "CryptixCrypto");
+
// XXX: IV of all zeroes is a minor security problem
IvParameterSpec iv = new IvParameterSpec( new byte[8] );
cipher.init(Cipher.ENCRYPT_MODE, key, iv);
@@ -340,26 +340,22 @@
public static byte[] decrypt(Key key, byte[] data, int offset, int len)
throws KeyException
{
+ logDebug("decrypt() called");
try {
- java.security.Cipher cipher =
- java.security.Cipher.getInstance(
- java.security.Cipher.getInstance(cipher_alg),
- (Mode)Mode.getInstance(cipher_mode),
- PaddingScheme.getInstance(cipher_padding) );
+ Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS#5",
+ "CryptixCrypto");
- cipher.initDecrypt(key);
-
- int zippedLen = cipher.doFinal(data, offset, len, data, 0);
+ // XXX: IV of all zeroes is a minor security problem
+ IvParameterSpec iv = new IvParameterSpec( new byte[8] );
+ cipher.init(Cipher.DECRYPT_MODE, key, iv);
+ byte[] zipped = cipher.doFinal(data, offset, len);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ByteArrayInputStream bais =
- new ByteArrayInputStream(data, 0, zippedLen);
-
+ ByteArrayInputStream bais = new ByteArrayInputStream(zipped);
GZIPInputStream gzis = new GZIPInputStream(bais);
byte[] buffer = new byte[4096];
len = 0;
- while (len >= 0)
- {
+ while (len >= 0) {
len = gzis.read(buffer, 0, buffer.length);
if (len > 0)
baos.write(buffer, 0, len);
@@ -368,15 +364,13 @@
return baos.toByteArray();
}
- catch (IOException e)
- {
+ catch (IOException e) {
e.printStackTrace(System.err);
throw new KeyException("IOException: "+e.getMessage());
}
- catch (NoSuchAlgorithmException e)
- {
- throw new ProviderException("Symmetric Algorithm (" + cipher_alg +
- ") not found ("+e.getMessage()+")");
+ catch (Exception e) {
+ e.printStackTrace(System.err);
+ throw new ProviderException();
}
}