Skip to content

Commit

Permalink
Remove Base64 (we depend on Java 1.8 so can use the native Base64 imp…
Browse files Browse the repository at this point in the history
…lementation) and FixedDOMOutputProcessor (only necessary for an old JDOM2 version without the fix for hunterhacker/jdom#115 )
  • Loading branch information
petergeneric committed May 5, 2015
1 parent 87ea68e commit d705e81
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 3,425 deletions.
@@ -1,6 +1,5 @@
package com.peterphi.std.crypto.digest;

import com.peterphi.std.util.Base64;
import com.peterphi.std.util.HexHelper;
import org.apache.commons.io.IOUtils;

Expand All @@ -16,6 +15,7 @@
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

Expand Down Expand Up @@ -165,7 +165,6 @@ public static byte[] digest(final InputStream is, final String algorithm) throws

// Finish the hash then convert it to a hex string
return md.digest();

}


Expand Down Expand Up @@ -223,7 +222,7 @@ public static String md5(File testFile) throws FileNotFoundException, IOExceptio

public static String md5(File testFile, int encoding) throws FileNotFoundException, IOException, NoSuchAlgorithmException
{
return digest(testFile, MD5, ENCODE_HEX);
return digest(testFile, MD5, encoding);
}


Expand All @@ -234,15 +233,9 @@ private static String encode(final byte[] in, final int method)
case ENCODE_HEX:
return HexHelper.toHex(in);
case ENCODE_BASE64:
return toB64(in);
return Base64.getEncoder().encodeToString(in);
default:
throw new IllegalArgumentException("Unsupported encoding method!");
}
}


private static String toB64(final byte[] in)
{
return Base64.encodeBytes(in);
}
}
@@ -1,7 +1,6 @@
package com.peterphi.std.crypto.digest.impl;

import com.peterphi.std.crypto.digest.IDigester;
import com.peterphi.std.util.Base64;
import com.peterphi.std.util.HexHelper;

import java.io.File;
Expand All @@ -18,7 +17,6 @@ public abstract class AbstractDigester implements IDigester
public static enum DigestEncoding
{
HEX,
BASE64;
}

private final DigestEncoding encoding;
Expand Down Expand Up @@ -79,8 +77,6 @@ protected final String encode(byte[] unencoded)
{
case HEX:
return HexHelper.toHex(unencoded);
case BASE64:
return Base64.encodeBytes(unencoded);
default:
throw new IllegalArgumentException("Illegal encoding: " + encoding);
}
Expand Down

0 comments on commit d705e81

Please sign in to comment.