package kr.co.hanwha.hifive.util;

import android.support.annotation.NonNull;

import java.security.MessageDigest;

/**
 * Created by sanghoonkwon on 2018. 1. 11..
 */

public class HFCryptoUtil {
    public static String getSHA256EncryptionData(String data) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(data.getBytes("UTF-8"));
            StringBuffer hexString = new StringBuffer();

            for (int i = 0; i < hash.length; i++) {
                String hex = Integer.toHexString(0xff & hash[i]);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }

            return hexString.toString();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public static String getEncAuthcodeSHA256(@NonNull String login_id, @NonNull String authcode){
        return getSHA256EncryptionData(login_id + "__newgw1!~" + authcode);
    }
}
