use of java.security.MessageDigest in project hadoop by apache.
the class ITestJets3tNativeFileSystemStore method writeRenameReadCompare.
protected void writeRenameReadCompare(Path path, long len) throws IOException, NoSuchAlgorithmException {
// If len > fs.s3n.multipart.uploads.block.size,
// we'll use a multipart upload copy
MessageDigest digest = MessageDigest.getInstance("MD5");
OutputStream out = new BufferedOutputStream(new DigestOutputStream(fs.create(path, false), digest));
for (long i = 0; i < len; i++) {
out.write('Q');
}
out.flush();
out.close();
assertTrue("Exists", fs.exists(path));
// Depending on if this file is over 5 GB or not,
// rename will cause a multipart upload copy
Path copyPath = path.suffix(".copy");
fs.rename(path, copyPath);
assertTrue("Copy exists", fs.exists(copyPath));
// Download file from S3 and compare the digest against the original
MessageDigest digest2 = MessageDigest.getInstance("MD5");
InputStream in = new BufferedInputStream(new DigestInputStream(fs.open(copyPath), digest2));
long copyLen = 0;
while (in.read() != -1) {
copyLen++;
}
in.close();
assertEquals("Copy length matches original", len, copyLen);
assertArrayEquals("Digests match", digest.digest(), digest2.digest());
}
use of java.security.MessageDigest in project hbase by apache.
the class Encryption method hash128.
/**
* Return the MD5 digest of the concatenation of the supplied arguments.
*/
public static byte[] hash128(byte[]... args) {
byte[] result = new byte[16];
try {
MessageDigest md = MessageDigest.getInstance("MD5");
for (byte[] arg : args) {
md.update(arg);
}
md.digest(result, 0, result.length);
return result;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (DigestException e) {
throw new RuntimeException(e);
}
}
use of java.security.MessageDigest in project hbase by apache.
the class Encryption method hash128.
/**
* Return the MD5 digest of the concatenation of the supplied arguments.
*/
public static byte[] hash128(String... args) {
byte[] result = new byte[16];
try {
MessageDigest md = MessageDigest.getInstance("MD5");
for (String arg : args) {
md.update(Bytes.toBytes(arg));
}
md.digest(result, 0, result.length);
return result;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (DigestException e) {
throw new RuntimeException(e);
}
}
use of java.security.MessageDigest in project hive by apache.
the class ProxyLocalFileSystem method getMD5Checksum.
/**
* Calculate MD5 checksum from data in FSDataInputStream
* @param fsInputStream
* @return byte array with md5 checksum bytes
* @throws Exception
*/
static byte[] getMD5Checksum(FSDataInputStream fsInputStream) throws Exception {
byte[] buffer = new byte[1024];
MessageDigest md5Digest = MessageDigest.getInstance("MD5");
int numRead = 0;
while (numRead != -1) {
numRead = fsInputStream.read(buffer);
if (numRead > 0) {
md5Digest.update(buffer, 0, numRead);
}
}
fsInputStream.close();
return md5Digest.digest();
}
use of java.security.MessageDigest in project qpid by apache.
the class SchemaClass method generateHash.
/**
* Return a hash generated over the body of the schema, and return a representation of the hash
* @return a hash generated over the body of the schema, and return a representation of the hash
*/
public final UUID generateHash() {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
updateHash(md5);
return UUID.nameUUIDFromBytes(md5.digest());
} catch (NoSuchAlgorithmException nsae) {
}
return null;
}
Aggregations