/** * See {@link #apr1Crypt(String, String)} for details. * * @param keyBytes * plaintext string to hash. * @return the hash value * @throws RuntimeException * when a {@link java.security.NoSuchAlgorithmException} is caught. * */ public static String apr1Crypt(final byte[] keyBytes) { return apr1Crypt(keyBytes, APR1_PREFIX + B64.getRandomSalt(8)); }
/** * Generates a libc6 crypt() compatible "$1$" hash value. * <p> * See {@link Crypt#crypt(String, String)} for details. * * @param keyBytes * plaintext string to hash. * @return the hash value * @throws RuntimeException * when a {@link java.security.NoSuchAlgorithmException} is caught. */ public static String md5Crypt(final byte[] keyBytes) { return md5Crypt(keyBytes, MD5_PREFIX + B64.getRandomSalt(8)); }
/** * Returns an MD5 MessageDigest. * * @return An MD5 digest instance. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught, which should never happen because MD5 is a * built-in algorithm * @see MessageDigestAlgorithms#MD5 */ public static MessageDigest getMd5Digest() { return getDigest(MessageDigestAlgorithms.MD5); }
private byte[] digestTestData() throws IOException { return DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData()); }
/** * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>. * * @param data * Data to digest * @return MD2 digest * @throws IOException * On error reading from the stream * @since 1.7 */ public static byte[] md2(final InputStream data) throws IOException { return digest(getMd2Digest(), data); }
/** * Generates a crypt(3) compatible hash using the DES algorithm. * <p> * As no salt is given, a random one will be used. * * @param original * plaintext password * @return a 13 character string starting with the salt string */ public static String crypt(final byte[] original) { return crypt(original, null); }
/** * Creates an instance using the provided algorithm type. * * @param algorithm to use * @param key the key to use * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @since 1.11 */ public HmacUtils(final String algorithm, final byte[] key) { this(getInitializedMac(algorithm, key)); }
private static int fourBytesToInt(final byte b[], int offset) { int value = byteToUnsigned(b[offset++]); value |= byteToUnsigned(b[offset++]) << 8; value |= byteToUnsigned(b[offset++]) << 16; value |= byteToUnsigned(b[offset++]) << 24; return value; }
/** * Creates an instance using the provided algorithm type. * * @param algorithm to use. * @param key the key to use * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @since 1.11 */ public HmacUtils(final HmacAlgorithms algorithm, final byte[] key) { this(algorithm.getName(), key); }
@Override public void update(final int b) { oneByte[0] = (byte) (b & 0xff); update(oneByte, 0, 1); }
/** Create a new PureJavaCrc32 object. */ public PureJavaCrc32C() { reset(); }
/** * Creates an XXHash32 instance. * @param seed the seed to use */ public XXHash32(final int seed) { this.seed = seed; initializeState(); }
/** Create a new PureJavaCrc32 object. */ public PureJavaCrc32() { _reset(); }
public static void main(final String args[]) throws Exception { printSystemProperties(System.out); doBench(CRCS, System.out); }
/** * Test whether the algorithm is supported. * @param messageDigestAlgorithm the algorithm name * @return {@code true} if the algorithm can be found * @since 1.11 */ public static boolean isAvailable(final String messageDigestAlgorithm) { return getDigest(messageDigestAlgorithm, null) != null; }
@Override public void reset() { initializeState(); totalLen = 0; pos = 0; }
@Override public void reset() { _reset(); }
/** * Returns an MD2 MessageDigest. * * @return An MD2 digest instance. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught, which should never happen because MD2 is a * built-in algorithm * @see MessageDigestAlgorithms#MD2 * @since 1.7 */ public static MessageDigest getMd2Digest() { return getDigest(MessageDigestAlgorithms.MD2); }
/** * Returns an SHA-1 digest. * * @return An SHA-1 digest instance. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught, which should never happen because SHA-1 is a * built-in algorithm * @see MessageDigestAlgorithms#SHA_1 * @since 1.7 */ public static MessageDigest getSha1Digest() { return getDigest(MessageDigestAlgorithms.SHA_1); }