bt.service.CryptoUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bt-core Show documentation
Show all versions of bt-core Show documentation
BitTorrent Client Library (Core)
package bt.service;
import bt.BtException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* This utility class provides cryptographic functions.
*
* @since 1.0
*/
public class CryptoUtil {
/**
* Calculate SHA-1 digest of a byte array.
*
* @since 1.0
*/
public static byte[] getSha1Digest(byte[] bytes) {
MessageDigest cryptor;
try {
cryptor = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
throw new BtException("Unexpected error", e);
}
return cryptor.digest(bytes);
}
}