package com.sonic.sdk.api.utils;

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

public class MD5Utils {


    public static String stringToMD5(String plainText) {
        byte[] secretBytes = null;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(
                    plainText.getBytes());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("没有这个md5算法！");
        }
        String md5code = new BigInteger(1, secretBytes).toString(16);
        final int length =  md5code.length();
        for (int i = 0; i < 32 - length; i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }


    public static void main(String[] args) throws Exception {

        String token = "WRTRthzsN07fq1i2";
        String mix = "90e8kDQUIWpXg8Jp";
        String content =  "{\n" +
                "    \"productId\":164\n" +
                "}";
        String key = stringToMD5("Pxtw10SD").toUpperCase();
        System.out.println("key: "+key.getBytes().length*8);
        System.out.println(key);

        System.out.println("加密后:"+  AesEncodeUtil.encrypt(content,key));
        String encoded =

                "4yRTJ9vP+DTRhZ4vq8EIPLTlEEgFj2qmGj0bwamDpnWRXCyNiaVpJP64EnowPMURgf3L15m5IGzupXKQev8J1fMYj4maoVZEJcEkEOplOLA=";
      // key ="F77D3FBE46C0333ED5B6D5A84B99EAE4";
        String decode = AesEncodeUtil.decrypt(    encoded,key);
        System.out.println("解密后"+decode);
    }





}