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

com.cx.restclient.sca.utils.fingerprints.Sha1SignatureCalculator Maven / Gradle / Ivy

There is a newer version: 2024.3.26
Show newest version
package com.cx.restclient.sca.utils.fingerprints;

import com.cx.restclient.exception.CxClientException;
import org.apache.commons.codec.binary.Hex;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Sha1SignatureCalculator implements SignatureCalculator {


    private static final String SHA1_SIGNATURE_TYPE_NAME = "SHA1";

    @Override
    public CxSCAFileSignature calculateSignature(byte[] content) throws CxClientException {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new CxClientException("Unable to use SHA-1 algorithm", e);
        }

        digest.update(content);

        return new CxSCAFileSignature(SHA1_SIGNATURE_TYPE_NAME, Hex.encodeHexString(digest.digest()));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy