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

ai.databand.id.Sha1 Maven / Gradle / Ivy

There is a newer version: 1.0.28.1
Show newest version
/*
 * © Copyright Databand.ai, an IBM Company 2022
 */

package ai.databand.id;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class Sha1 {

    private final byte[] value;

    public Sha1(String namespace, String name) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] namespaceBytes = namespace.getBytes();
            byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
            byte[] both = Arrays.copyOf(namespaceBytes, namespaceBytes.length + nameBytes.length);
            System.arraycopy(nameBytes, 0, both, namespaceBytes.length, nameBytes.length);
            value = md.digest(both);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Unable to get SHA-1 digest");
        }
    }

    public byte[] value() {
        return value;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy