package com.mortals.xhx.common.security;


import com.mortals.framework.util.security.sm.SM2Utils;
import com.mortals.framework.util.security.sm.SM4Utils;
import com.mortals.framework.util.security.sm.SMCipher;
import com.mortals.framework.util.security.sm.Util;
import org.apache.commons.codec.binary.Base64;

import static com.mortals.framework.util.security.sm.SM2Utils.encrypt;

/**
 * 服务调用示例
 *
 */
public class TestDemo {
    public static void main(String[] args) throws Exception {
        String plainText = "{\"fwid\":\"511010020304102\",\"machine\":{\"mac\":\"10-63-C8-30-B1-F9\",\"ip\":\"192.168.78.158\",\"zdbm\":\"DCKJ0100201706010653000000000000\"},\"data\":{\"qrcode\":\"5101000001177421384867\"}}";
        SM4Utils sm4 = new SM4Utils();
        sm4.setSecretKey("1234567890123456");

        System.out.println("明文: " + plainText);
        String transformation = "SM4/ECB/Padding";
        SMCipher clipher = SMCipher.getInstance(transformation);
        clipher.init(1, sm4.getSecretKey().getBytes(), sm4.getIv().getBytes());
        byte[] result = clipher.doFinal(plainText.getBytes());
        System.out.println(Base64.encodeBase64URLSafeString(result));


/*        SM2Utils sm2Utils = new SM2Utils();
        SM2Utils.generateKeyPair();
        String plainText = "ererfeiisgod";
        byte[] sourceData = plainText.getBytes();
        //私钥
        String prik = "3690655E33D5EA3D9A4AE1A1ADD766FDEA045CDEAA43A9206FB8C430CEFE0D94";
        //公钥
        String pubk = "04F6E0C3345AE42B51E06BF50B98834988D54EBC7460FE135A48171BC0629EAE205EEDE253A530608178A98F1E19BB737302813BA39ED3FA3C51639D7A20C7391A";
        System.out.println("\u52a0\u5bc6: ");
        String cipherText = encrypt(Util.hexToByte(pubk), sourceData);
        System.out.println(cipherText);*/


    }
}
