Example usage for com.google.common.hash Hashing sipHash24

List of usage examples for com.google.common.hash Hashing sipHash24

Introduction

In this page you can find the example usage for com.google.common.hash Hashing sipHash24.

Prototype

public static HashFunction sipHash24() 

Source Link

Document

Returns a hash function implementing the <a href="https://131002.net/siphash/">64-bit SipHash-2-4 algorithm</a> using a seed value of k = 00 01 02 ...

Usage

From source file:com.lithium.flow.util.HashFunctions.java

@Nonnull
public static HashFunction of(@Nonnull String name) {
    checkNotNull(name);//  w w w  .  java  2  s . c o  m
    switch (name) {
    case "adler32":
        return Hashing.adler32();
    case "crc32":
        return Hashing.crc32();
    case "md5":
        return Hashing.md5();
    case "sha1":
        return Hashing.sha1();
    case "sha256":
        return Hashing.sha256();
    case "sha512":
        return Hashing.sha512();
    case "sipHash24":
        return Hashing.sipHash24();
    case "murmur3_32":
        return Hashing.murmur3_32();
    case "murmur3_128":
        return Hashing.murmur3_128();
    default:
        throw new RuntimeException("unknown hash: " + name);
    }
}

From source file:app.data.model.Link.java

@JsonCreator
public Link(@JsonProperty(value = "url") String url, @JsonProperty(value = "title") String title) {
    this.url = url;
    this.title = title;
    //  1/(0.5% * 0.5%)? 50 ????
    this.urlUnique = Hashing.murmur3_128().hashString(url, StandardCharsets.UTF_8).toString()
            + Hashing.sipHash24().hashString(url, StandardCharsets.UTF_8);
}

From source file:org.locationtech.geogig.web.api.commands.RequestDeleteRepositoryToken.java

/**
 * Runs the command and builds the appropriate response
 * /* www  . java2 s.c  o  m*/
 * @param context - the context to use for this command
 * 
 * @throws CommandSpecException
 */
@Override
protected void runInternal(CommandContext context) {
    final Context geogig = this.getRepositoryContext(context);

    SecureRandom rnd = new SecureRandom();
    byte[] bytes = new byte[128];
    rnd.nextBytes(bytes);
    String deleteToken = Hashing.sipHash24().hashBytes(bytes).toString();

    final String deleteKey = DeleteRepository.deleteKeyForToken(deleteToken);

    final long now = geogig.platform().currentTimeMillis();
    byte[] nowBytes = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(now).array();

    final BlobStore blobStore = geogig.repository().blobStore();
    blobStore.putBlob(deleteKey, nowBytes);
    deleteTokenExecutor.schedule(new Runnable() {

        private Repository repo = context.getRepository();

        @Override
        public void run() {
            if (repo.isOpen()) {
                BlobStore blobs = repo.blobStore();
                blobs.removeBlob(deleteKey);
            }

        }
    }, 60, TimeUnit.SECONDS);

    context.setResponseContent(new CommandResponse() {
        @Override
        public void write(ResponseWriter out) throws Exception {
            out.start();
            out.writeElement("token", deleteToken);
            out.finish();
        }
    });
}

From source file:com.stegosaurus.stegosaurus.StegosaurusModule.java

@Override
protected void configure() {
    install(new SteganographersModule(buildGeneticParams()));
    install(new GeneticModule());
    bind(ByteBufferHelper.class).to(ByteBufferHelperImpl.class);
    bind(PermutationProvider.class).to(DefaultPermutationProvider.class);
    bind(ListeningExecutorService.class).toProvider(ListeningExecutorServiceProvider.class);
    bind(HashFunction.class).toInstance(Hashing.sipHash24());
    bind(Charset.class).toInstance(Charset.defaultCharset());
    bind(StegosaurusFacade.class).to(StegosaurusFacadeImpl.class);
}

From source file:lbaas.util.HashAlgorithm.java

public int hash(Object key) {
    HashCode hashCode;//from w  w w  .j a  v a 2 s  .c o  m
    HashFunction hashAlgorithm;
    switch (hashType) {
    case MD5:
        hashAlgorithm = Hashing.md5();
        break;
    case MURMUR3_32:
        hashAlgorithm = Hashing.murmur3_32();
        break;
    case SHA256:
        hashAlgorithm = Hashing.sha256();
        break;
    case SIP24:
        hashAlgorithm = Hashing.sipHash24();
        break;
    default:
        hashAlgorithm = Hashing.sipHash24();
        break;
    }
    if (key instanceof String) {
        hashCode = hashAlgorithm.newHasher().putString((String) key, Charsets.UTF_8).hash();
    } else if (key instanceof Long) {
        hashCode = hashAlgorithm.newHasher().putLong((Long) key).hash();
    } else {
        hashCode = hashAlgorithm.newHasher().hash();
    }
    return hashCode.asInt();
}

From source file:org.knime.ext.textprocessing.nodes.transformation.documentvectorhashing.Siphash24HashingFunction.java

/**
 * {@inheritDoc}/*from w w w  .  ja  va  2s.  co  m*/
 */
@Override
public int hash(final String term, final int seed) {
    HashFunction hash = Hashing.sipHash24();
    HashCode hashCode = hash.hashString(term, Charsets.UTF_8);
    return hashCode.asInt();
}

From source file:com.globo.galeb.consistenthash.HashAlgorithm.java

/**
 * Calc Hash./* ww w.ja v a 2s  . c o  m*/
 *
 * @param key the key
 * @return int hash
 */
public HashAlgorithm hash(Object key) {
    HashFunction hashAlgorithm;
    switch (hashType) {
    case MD5:
        hashAlgorithm = Hashing.md5();
        break;
    case MURMUR3_32:
        hashAlgorithm = Hashing.murmur3_32();
        break;
    case SHA256:
        hashAlgorithm = Hashing.sha256();
        break;
    case SIP24:
        hashAlgorithm = Hashing.sipHash24();
        break;
    default:
        hashAlgorithm = Hashing.sipHash24();
        break;
    }
    if (key instanceof String) {
        hashCode = hashAlgorithm.newHasher().putString((String) key, Charsets.UTF_8).hash();
    } else if (key instanceof Long) {
        hashCode = hashAlgorithm.newHasher().putLong((Long) key).hash();
    } else {
        hashCode = hashAlgorithm.newHasher().hash();
    }
    return this;
}

From source file:org.locationtech.geogig.repository.impl.FileRepositoryResolver.java

@Override
public URI buildRepoURI(URI rootRepoURI, String repoName) {
    final File rootDirectory = toFile(rootRepoURI);
    // Look up repo ID for repo name, if it does not exist, generate a new one
    String repoId = reposUnderRootDirectory(rootDirectory).get(repoName);
    if (repoId == null) {
        SecureRandom rnd = new SecureRandom();
        byte[] bytes = new byte[128];
        rnd.nextBytes(bytes);/*w w w  . ja  va 2s  . co m*/
        repoId = Hashing.sipHash24().hashBytes(bytes).toString();
    }

    File repoDirectory = new File(rootDirectory, repoId);
    return repoDirectory.toURI();
}

From source file:org.lightjason.agentspeak.action.builtin.crypto.CHash.java

/**
 * runs hashing function with difference between Google Guava hashing and Java default digest
 *
 * @param p_context execution context//from ww w.jav  a2s  .c o  m
 * @param p_algorithm algorithm name
 * @param p_data byte data representation
 * @return hash value
 */
private static String hash(@Nonnull final IContext p_context, @Nonnull final String p_algorithm,
        @Nonnull final byte[] p_data) {
    switch (p_algorithm.trim().toLowerCase(Locale.ROOT)) {
    case "adler-32":
        return Hashing.adler32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32":
        return Hashing.crc32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32c":
        return Hashing.crc32c().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-32":
        return Hashing.murmur3_32().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-128":
        return Hashing.murmur3_128().newHasher().putBytes(p_data).hash().toString();

    case "siphash-2-4":
        return Hashing.sipHash24().newHasher().putBytes(p_data).hash().toString();

    default:
        try {
            return BaseEncoding.base16().encode(MessageDigest.getInstance(p_algorithm).digest(p_data))
                    .toLowerCase(Locale.ROOT);
        } catch (final NoSuchAlgorithmException l_exception) {
            throw new CRuntimeException(l_exception, p_context);
        }
    }
}

From source file:org.lightjason.agentspeak.action.buildin.crypto.CHash.java

/**
 * runs hashing function with difference between Google Guava hashing and Java default digest
 *
 * @param p_algorithm algorithm name// www.  j  ava2 s  .c  o m
 * @param p_data byte data representation
 * @return hash value
 *
 * @throws NoSuchAlgorithmException on unknown hashing algorithm
 */
private String hash(final String p_algorithm, final byte[] p_data) throws NoSuchAlgorithmException {
    switch (p_algorithm.trim().toLowerCase(Locale.ROOT)) {
    case "adler-32":
        return Hashing.adler32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32":
        return Hashing.crc32().newHasher().putBytes(p_data).hash().toString();

    case "crc-32c":
        return Hashing.crc32c().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-32":
        return Hashing.murmur3_32().newHasher().putBytes(p_data).hash().toString();

    case "murmur3-128":
        return Hashing.murmur3_128().newHasher().putBytes(p_data).hash().toString();

    case "siphash-2-4":
        return Hashing.sipHash24().newHasher().putBytes(p_data).hash().toString();

    default:
        return String.format("%032x", new BigInteger(1, MessageDigest.getInstance(p_algorithm).digest(p_data)));
    }
}