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

com.absmartly.sdk.internal.hashing.Hashing Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
package com.absmartly.sdk.internal.hashing;

import com.absmartly.sdk.internal.Buffers;

public abstract class Hashing {
	private Hashing() {}

	private static ThreadLocal threadBuffer = new ThreadLocal() {
		@Override
		public byte[] initialValue() {
			return new byte[512];
		}
	};

	public static byte[] hashUnit(CharSequence unit) {
		final int n = unit.length();
		final int bufferLen = n << 1;

		byte[] buffer = threadBuffer.get();
		if (buffer.length < bufferLen) {
			final int bit = 32 - Integer.numberOfLeadingZeros(bufferLen - 1);
			buffer = new byte[1 << bit];
			threadBuffer.set(buffer);
		}

		final int encoded = Buffers.encodeUTF8(buffer, 0, unit);
		return MD5.digestBase64UrlNoPadding(buffer, 0, encoded);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy