use of java.security.MessageDigest in project platformlayer by platformlayer.
the class CryptoUtils method sha256.
public static Sha256Hash sha256(byte[]... data) {
MessageDigest digest = getSha256();
for (int i = 0; i < data.length - 1; i++) {
digest.update(data[i]);
}
byte[] hash = digest.digest(data[data.length - 1]);
return new Sha256Hash(hash);
}
use of java.security.MessageDigest in project cassandra by apache.
the class CacheProviderTest method assertDigests.
private void assertDigests(IRowCacheEntry one, CachedBTreePartition two) {
assertTrue(one instanceof CachedBTreePartition);
try {
MessageDigest d1 = MessageDigest.getInstance("MD5");
MessageDigest d2 = MessageDigest.getInstance("MD5");
UnfilteredRowIterators.digest(((CachedBTreePartition) one).unfilteredIterator(), d1, MessagingService.current_version);
UnfilteredRowIterators.digest(((CachedBTreePartition) two).unfilteredIterator(), d2, MessagingService.current_version);
assertTrue(MessageDigest.isEqual(d1.digest(), d2.digest()));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
use of java.security.MessageDigest in project cassandra by apache.
the class UUIDGen method hash.
private static byte[] hash(Collection<InetAddress> data) {
try {
// Identify the host.
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
for (InetAddress addr : data) messageDigest.update(addr.getAddress());
// Identify the process on the load: we use both the PID and class loader hash.
long pid = CLibrary.getProcessID();
if (pid < 0)
pid = new Random(System.currentTimeMillis()).nextLong();
FBUtilities.updateWithLong(messageDigest, pid);
ClassLoader loader = UUIDGen.class.getClassLoader();
int loaderId = loader != null ? System.identityHashCode(loader) : 0;
FBUtilities.updateWithInt(messageDigest, loaderId);
return messageDigest.digest();
} catch (NoSuchAlgorithmException nsae) {
throw new RuntimeException("MD5 digest algorithm is not available", nsae);
}
}
use of java.security.MessageDigest in project cassandra by apache.
the class PartitionTest method testDigest.
public void testDigest(int version) throws NoSuchAlgorithmException {
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_TENCOL);
try {
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 5, "key1").clustering("c").add("val", "val1");
for (int i = 0; i < 10; i++) builder.add("val" + i, "val" + i);
builder.build().applyUnsafe();
new RowUpdateBuilder(cfs.metadata(), 5, "key2").clustering("c").add("val", "val2").build().applyUnsafe();
ReadCommand cmd1 = Util.cmd(cfs, "key1").build();
ReadCommand cmd2 = Util.cmd(cfs, "key2").build();
ImmutableBTreePartition p1 = Util.getOnlyPartitionUnfiltered(cmd1);
ImmutableBTreePartition p2 = Util.getOnlyPartitionUnfiltered(cmd2);
MessageDigest digest1 = MessageDigest.getInstance("MD5");
MessageDigest digest2 = MessageDigest.getInstance("MD5");
UnfilteredRowIterators.digest(p1.unfilteredIterator(), digest1, version);
UnfilteredRowIterators.digest(p2.unfilteredIterator(), digest2, version);
assertFalse(Arrays.equals(digest1.digest(), digest2.digest()));
p1 = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, "key2").build());
p2 = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, "key2").build());
digest1 = MessageDigest.getInstance("MD5");
digest2 = MessageDigest.getInstance("MD5");
UnfilteredRowIterators.digest(p1.unfilteredIterator(), digest1, version);
UnfilteredRowIterators.digest(p2.unfilteredIterator(), digest2, version);
assertTrue(Arrays.equals(digest1.digest(), digest2.digest()));
p1 = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, "key2").build());
RowUpdateBuilder.deleteRow(cfs.metadata(), 6, "key2", "c").applyUnsafe();
p2 = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, "key2").build());
digest1 = MessageDigest.getInstance("MD5");
digest2 = MessageDigest.getInstance("MD5");
UnfilteredRowIterators.digest(p1.unfilteredIterator(), digest1, version);
UnfilteredRowIterators.digest(p2.unfilteredIterator(), digest2, version);
assertFalse(Arrays.equals(digest1.digest(), digest2.digest()));
} finally {
cfs.truncateBlocking();
}
}
use of java.security.MessageDigest in project cassandra by apache.
the class ReadResponse method makeDigest.
protected static ByteBuffer makeDigest(UnfilteredPartitionIterator iterator, ReadCommand command) {
MessageDigest digest = FBUtilities.threadLocalMD5Digest();
UnfilteredPartitionIterators.digest(iterator, digest, command.digestVersion());
return ByteBuffer.wrap(digest.digest());
}
Aggregations