package org.bdware.sc.encrypt.test;

import org.bdware.sc.conn.ByteUtil;
import org.bdware.sc.encrypt.HardwareInfo;
import org.bdware.sc.encrypt.RSA;

import java.io.IOException;
import java.util.Arrays;

public class HardwareInfoTest {
    // {"action":"apply","arg":"{\"uuid\":\"MzkxMmQ0MDUtMjAyYy00NWE0LTk2ZjktMGQ1ZmMzOWFiN2Nl\",\"remark\":1660864742952}"}
    // {"action":"accept","arg":"{\"uuid\":\"MzkxMmQ0MDUtMjAyYy00NWE0LTk2ZjktMGQ1ZmMzOWFiN2Nl\",\"date\":1660864742952}"}
    public static void main(String[] args) throws IOException {
        System.out.println("CPUID:" + HardwareInfo.getCPUID());
        String key =
                "OTIzNmUzMGNmOGI1ZjFkMDBjZjEyMWY4OThmM2ZmYTIwNjE2ODYxOWNiMDNhMTVlM2FiZTA0OThhNTlkZDg1MmRiMjA5Njc1NmM3ZDBhOWM3YTNkOTg2NWVlYzk2YzM1MmY0MDdkMGMyOTA4M2NkNDI4YmY1YjM5M2U5OTA1NWE0MzM0MTJhM2Y2ZDhkZWVmZDk4MmI4NmZiZTMyYjhlMGE3ZWFmZmE5ODM3M2E4ZTRmNTYyNDgxNTY0Yjk2ZjFkMTZiODk2MGRhZDAwMTNjZDYwOGZmOTcxNjdiOWI1MDU1MjJlMzk0ODhmODczNDJjNWUwOGRjZjFhZjFkYzBjODUxZjRlNDg2ZWIyOTM5NDI3MDc4MjA5NDg5ODliODVhZDNlOGJlNWJiYWEzZDUyMWU2MjdmZjE3NGY4Y2ZlZDk3NTY4OWNlNDEzOGYyMTgyOWIwMDVmMzE0YjM3MmNlZmFkZjBkNmUyOTY4ZGUzZmFlNGUxNTFkMWFmNWE4Mjc4ZjQ2MDI5ODBjY2JkMDM0ZDE0YWRjZDk1ZjI1MjY3NmRlODRjYzdkNzU5NGYyYTAxMTliYWJmYjgyMGRjMWNjZWZjNThjNWUwYWRjMDQyM2MzYzA1ODNhZTU1MWZlN2Y5YTYwYjkxZjg2YWViNDNlMzU0NzlhYWI5YmFjOTAwN2IsMTAwMDEsODg1Yjk1YWRlMDM4ZDY1NWZmZWJkNTkxYTExYjU0OTkwNmYyNzQ4NzkzNzQ0NDQ2YmJhM2MwNjc5Nzc0Yjg2Y2I1MWQxNDE0NTg2M2Q4YzQ4YjlmZWMwMzhjMDhkZWQ4NGVjM2U2OWFiMzlkOTIxNTBlMTczZjdkMDg2YWVlYjlmYTE4OTMxNWM0YmQwNjU0NGFkNjg1MjhmOTA5MTZhZmI1MGEwY2ZhNGFiNDRmOWI4ZjU4ZTNmZWM3OWJjNDBiMmRjODYxNzA0OTk5ZGJkZGRhMjMwYjJmN2VkYjhhZmQ3NjYxZDM1YzVmMzY2OTJhYzM1YmEyYTllNjc1NjlmNjNkMjIwZDdhMmI5MGRjYmU3ZTA4NWE0ODhjZDY0YzhhNTc0MjY1NDI5NzJjMGU0MGJjZmM3ZDc2N2U5ZDFiNDU1NDUwMTFjYzZjOWExNjExNGIzMGNkZjBmYmI1MzA5NzI5MzA3ZTM1NWI5NjBlMjRmMzg0NDUyM2JjOWYxZDk4YzE1Yzk0MGUwNmYyM2FiNDk4MzA0ZGIzODZjZDU2MmYwMThmN2Y5OGQ3MzQ0YWQyNjFkY2MzZWIzYjZmODQ0MThjZWZmNGE3ZTYyMDc2NjY5ZDdhMGUwNjgxYzlhZTRkMWZhOWViMmVjNjg3M2ZlMDY2Mzk4ZTAzOTlkMTk4ODE=";
        RSA rsa = RSA.generateFromBase64(key);
        String data = HardwareInfo.getCPUID() + "=="
                + (System.currentTimeMillis() + 365L * 50L * 24L * 3600L * 1000L);
        byte[] bytes = data.getBytes();
        bytes = rsa.decode(bytes);
        // rsa = RSA.generateFromBase64(rsa.toBase64Pubkey());
        System.out.println("Data:" + data);
        System.out.println("======Generated Key:=====");
        System.out.println(ByteUtil.encodeBASE64(bytes).replaceAll("\n", ""));
        System.out.println("======Done:======");
        String encoded =
                "OWXJxeOhjmer/+2oBTXlLEOltiocVqBWsj/uW1mDoYFC+ikh2z9b7EQVDDDnz3TBOsfjs8+JpTYp4B6b2uYcrFww2WUrf78rB/WOqJ9domJXQ8w/3uiQwqNXecHByQ8488UtLLtvm5eNy9B7xtWzRqi/89X4A/sypIPxUe7NF4IXnameuC0GE/ZKdZeJKV5qn2deVBt7ApAPbsKSk55W5lOK/nLwAr8oK1QtFI0qKDhjVTbNobU16AOTzbhaijZpG102BkzrkoCeosnHOD8CMz3WT0P2H+hI9yXbvfNJTCw2tmo+Q1yeEjSQxgdXHEbKM6sdJiN35GXEiFXxXpDsNw==";
        bytes = rsa.encode(ByteUtil.decodeBASE64(encoded));
        System.out.println(new String(bytes));

        byte[] data2 = ByteUtil.decodeBASE64("MzkxMmQ0MDUtMjAyYy00NWE0LTk2ZjktMGQ1ZmMzOWFiN2Nl");
        String strr = new String(data2) + "==" + "1660864742952";

        System.out.println("Original:" + strr);
        byte[] decoded = rsa.decode(strr.getBytes());
        System.out.println("Hash:" + Arrays.hashCode(decoded));
        String newLicence = ByteUtil.encodeBASE64(decoded);
        System.out.println("newLicence:" + newLicence.replaceAll("\n", ""));
    }

    // OGJhYmY5Yjk0YzU1Y2RlMmE0Y2VhODE0YTE2NmMyYWNhZDMwZjNmNjdmZWUwY2M1MDNhODNlYTk3NjQxMGRiMGRjYzc5MDI4OTIzNDhiMTUxMmE2MWZmODJkOTFhMjAyMzIzYmJkMTA0MzMyZTJjMmQ3YmQxNTdkNTZjZWIzOGMyOWY4MWFiOTM1MzY0ZDEzMjY5ZDQzMTc0NWUyZDcyOGMwMTk0NmFlMDA0ZGY5OWQ1YzViNDUwMDRjMDgyOWE0YWFhZGQ2YTFjYjNiMmM3YjBhYzE3MTdjZGFkYzVhZTg1NTA2NTI4Mjg4MzBhNzMwNTExM2YwN2FiNWUyNmU3YWFmMzgwMDAyYTE1OTM0ZWQyOTA4YjViZTI0MTNiYmEwNDkwN2RkNDEzYjkwYzIzMmIxNmIyNTVlM2ZlYjg2ZDM2YTAzZGVmZTM1MTlhOTk4NzI3OD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