package com.lutao.cloud.auth.sso.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashUtil {

    public static int multiHashToInteger(String input) {
        try {
            BigInteger hashMD5 = generateHash(input, "MD5");
            BigInteger hashSHA256 = generateHash(input, "SHA-256");
            BigInteger hashSHA1 = generateHash(input, "SHA-1");

            BigInteger combinedHash = hashMD5.xor(hashSHA256).xor(hashSHA1);

            return combinedHash.mod(BigInteger.valueOf(Integer.MAX_VALUE)).intValue();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Hash algorithm not supported", e);
        }
    }

    private static BigInteger generateHash(String input, String algorithm) throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance(algorithm);
        byte[] hash = digest.digest(input.getBytes());
        return new BigInteger(1, hash);
    }
}