package com.cusc.nirvana.user.rnr.fp.util;

import org.bouncycastle.crypto.digests.SM3Digest;

/**
 * Description RnrDataSM3Utils function
 *
 * @author zx
 * @version 1.0
 * @date 2022-06-16 17:20
 */
public class RnrDataSM3Utils {

    public static String encode(String context) {
        return ZTSecurityUtil.toString(encode(ZTSecurityUtil.toBytes(context)));
    }

    public static byte[] encode(byte[] context) {
        SM3Digest sm3 = new SM3Digest();
        sm3.update(context, 0, context.length);
        byte[] hash = new byte[sm3.getDigestSize()];
        sm3.doFinal(hash, 0);
        String hexText = ZTSecurityUtil.toHexString(hash);
        return ZTSecurityUtil.toBytes(hexText);
    }

    public static void main(String[] args) {
        String text = "123sdfq";
        System.out.println(encode(text));
        // 48ae4d7348bab584c92da40d89a141acdb91e648f88825cc9c2363dc24a36e8c
    }
}
