All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.libg.cryptography.MD5 Maven / Gradle / Ivy

There is a newer version: 7.1.0
Show newest version
package aQute.libg.cryptography;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 extends Digest {
	public final static String ALGORITHM = "MD5";

	public static Digester getDigester(OutputStream... out) throws Exception {
		return new Digester(MessageDigest.getInstance(ALGORITHM), out) {

			@Override
			public MD5 digest() throws Exception {
				return new MD5(md.digest());
			}

			@Override
			public MD5 digest(byte[] bytes) {
				return new MD5(bytes);
			}

			@Override
			public String getAlgorithm() {
				return ALGORITHM;
			}
		};
	}

	public MD5(byte[] digest) {
		super(digest, 16);
	}

	@Override
	public String getAlgorithm() {
		return ALGORITHM;
	}

	public static MD5 digest(byte[] data) throws Exception {
		return getDigester().from(data);
	}

	public static MD5 digest(File f) throws NoSuchAlgorithmException, Exception {
		return getDigester().from(f);
	}

	public static MD5 digest(InputStream f) throws NoSuchAlgorithmException, Exception {
		return getDigester().from(f);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy