use of java.security.MessageDigest in project storm by apache.
the class VersionInfoMojo method computeMD5.
private byte[] computeMD5(List<File> files) throws IOException, NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
for (File file : files) {
getLog().debug("Computing MD5 for: " + file);
md5.update(readFile(file));
}
return md5.digest();
}
use of java.security.MessageDigest in project hive by apache.
the class TestHBaseStore method hashSd.
@Test
public void hashSd() throws Exception {
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(new FieldSchema("col1", "int", ""));
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", true, 0, serde, null, null, emptyParameters);
Map<List<String>, String> map = new HashMap<List<String>, String>();
map.put(Arrays.asList("col3"), "col4");
SkewedInfo skew = new SkewedInfo(Arrays.asList("col1"), Arrays.asList(Arrays.asList("col2")), map);
sd.setSkewedInfo(skew);
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] baseHash = HBaseUtils.hashStorageDescriptor(sd, md);
StorageDescriptor changeSchema = new StorageDescriptor(sd);
changeSchema.getCols().add(new FieldSchema("col2", "varchar(32)", "a comment"));
byte[] schemaHash = HBaseUtils.hashStorageDescriptor(changeSchema, md);
Assert.assertFalse(Arrays.equals(baseHash, schemaHash));
StorageDescriptor changeLocation = new StorageDescriptor(sd);
changeLocation.setLocation("file:/somewhere/else");
byte[] locationHash = HBaseUtils.hashStorageDescriptor(changeLocation, md);
Assert.assertArrayEquals(baseHash, locationHash);
}
use of java.security.MessageDigest in project storm by apache.
the class AuthUtilsTest method makeDigestPayloadTest.
@Test
public void makeDigestPayloadTest() throws NoSuchAlgorithmException {
String section = "user-pass-section";
Map<String, String> optionMap = new HashMap<String, String>();
String user = "user";
String pass = "pass";
optionMap.put("username", user);
optionMap.put("password", pass);
AppConfigurationEntry entry = Mockito.mock(AppConfigurationEntry.class);
Mockito.<Map<String, ?>>when(entry.getOptions()).thenReturn(optionMap);
Configuration mockConfig = Mockito.mock(Configuration.class);
Mockito.when(mockConfig.getAppConfigurationEntry(section)).thenReturn(new AppConfigurationEntry[] { entry });
MessageDigest digest = MessageDigest.getInstance("SHA-512");
byte[] output = digest.digest((user + ":" + pass).getBytes());
String sha = Hex.encodeHexString(output);
// previous code used this method to generate the string, ensure the two match
StringBuilder builder = new StringBuilder();
for (byte b : output) {
builder.append(String.format("%02x", b));
}
String stringFormatMethod = builder.toString();
Assert.assertEquals(AuthUtils.makeDigestPayload(mockConfig, "user-pass-section"), sha);
Assert.assertEquals(sha, stringFormatMethod);
}
use of java.security.MessageDigest in project tomcat by apache.
the class ConcurrentMessageDigest method init.
/**
* Ensures that {@link #digest(String, byte[][])} will support the specified
* algorithm. This method <b>must</b> be called and return successfully
* before using {@link #digest(String, byte[][])}.
*
* @param algorithm The message digest algorithm to be supported
*
* @throws NoSuchAlgorithmException If the algorithm is not supported by the
* JVM
*/
public static void init(String algorithm) throws NoSuchAlgorithmException {
synchronized (queues) {
if (!queues.containsKey(algorithm)) {
MessageDigest md = MessageDigest.getInstance(algorithm);
Queue<MessageDigest> queue = new ConcurrentLinkedQueue<>();
queue.add(md);
queues.put(algorithm, queue);
}
}
}
use of java.security.MessageDigest in project tomcat by apache.
the class ConcurrentMessageDigest method digest.
public static byte[] digest(String algorithm, int rounds, byte[]... input) {
Queue<MessageDigest> queue = queues.get(algorithm);
if (queue == null) {
throw new IllegalStateException("Must call init() first");
}
MessageDigest md = queue.poll();
if (md == null) {
try {
md = MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
// first.
throw new IllegalStateException("Must call init() first");
}
}
// Round 1
for (byte[] bytes : input) {
md.update(bytes);
}
byte[] result = md.digest();
// Subsequent rounds
if (rounds > 1) {
for (int i = 1; i < rounds; i++) {
md.update(result);
result = md.digest();
}
}
queue.add(md);
return result;
}
Aggregations