//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.library.TopUp.mefont;

import java.io.FileInputStream;
import java.net.URLDecoder;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;

public class MetfoneRSAUtils {
    static final String pripath = "/com/library/TopUp/mefont/keys/LASIA.pri";
    static final String pubpath = "/com/library/TopUp/mefont/keys/LASIA.pub";

    public MetfoneRSAUtils() {
    }

    public static String encryptRSA(String plainData) {
        try {
            String path = MetfoneRSAUtils.class.getResource("/").toString();
            path = "/" + path.substring(6, path.length() - 1);
            path = URLDecoder.decode(path) + "/com/library/TopUp/mefont/keys/LASIA.pub";
            FileInputStream fis = new FileInputStream(path);
            byte[] byteKeyFromFile = new byte[fis.available()];
            fis.read(byteKeyFromFile);
            fis.close();
            X509EncodedKeySpec keySpec = new X509EncodedKeySpec(byteKeyFromFile);
            KeyFactory factory = KeyFactory.getInstance("RSA");
            PublicKey pubKey = factory.generatePublic(keySpec);
            Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            c.init(1, pubKey);
            byte[] encryptedByte = c.doFinal(plainData.getBytes());
            String encrypted = Base64.encodeBase64String(encryptedByte);
            return encrypted;
        } catch (Exception var10) {
            System.out.println(var10.getLocalizedMessage());
            return null;
        }
    }

    public static String decryptRSA(String encryptedData) {
        try {
            String path = MetfoneRSAUtils.class.getResource("/").toString();
            path = "/" + path.substring(6, path.length() - 1);
            path = URLDecoder.decode(path) + "/com/library/TopUp/mefont/keys/LASIA.pri";
            FileInputStream fis = new FileInputStream(path);
            byte[] byteKeyFromFile = new byte[fis.available()];
            fis.read(byteKeyFromFile);
            fis.close();
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(byteKeyFromFile);
            KeyFactory factory = KeyFactory.getInstance("RSA");
            PrivateKey priKey = factory.generatePrivate(keySpec);
            Cipher c2 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            c2.init(2, priKey);
            String decrypted = new String(c2.doFinal(Base64.decodeBase64(encryptedData)));
            return decrypted;
        } catch (Exception var9) {
            System.out.println(var9.getLocalizedMessage());
            return null;
        }
    }

    public static void main(String[] args) {
        String token = "NTKenRyiwOW5xaXnWm/2+HHuTsy4o4dA59J3uVs8bQM+C+Wt/KQM2jjeRHKlAi0UswHabwpRAn+/KBaZtI/MO/ysOa4eEtZCEFui5u5SsKC/iZPxFVA30xlriORaYd7vX3rXvr3I1wNkFromkyATxDWPg3JCUj+soakh9M2SRt54Qa4NxbgsNGgesAHJKQ1JWQglv5pklyVWN7THj1aMjcdq7aigEZgcPI01/+r5Wcwe1pvJx5hH0I3CYRZY+BVM/Jm1g6E17sd3bOT2f7G3ARmFA6i5mgDReZGZpLmx2TogVY+EAGUAZE3LrtBwlzkV5gLrnh+WIZ9nMG7GkTxNFA==";
        String token2 = "iljUgme83Rj3dCvhFHwFdBB+DXkPpmxTjSFGlsjJJeXQRmQRP62lO9lNYGBkz827TPOjrycRg0BuPLH4I497iuMo7LUMt0mg3C7B3ejRkgcqWoiQxaSjB79mQa8lip/w6Q9S74Wwim/tDw/horrQ/a50+sTe+UYuHh1hjwnr61KQwieNDRFC3rYxeA5WkwpMCVQMHWfTqK3mPjXHqJgoMySUekg0NCbYQYmqWsgetakUuSlaKmrjpK90WfjOsnIeuTWEYHh+tlrI3VVIGF/Pknw6xzLOG+rTi1IZ7RkuHKh8nbiR4uLDkXpvGiiL1Hiq3H2Sz897MZKs1HeqWdrMng==";
        String str = decryptRSA(token);
        String encryptText = str + "|682504";
        String retStr = encryptRSA(encryptText);
        System.out.println("解密后的数据：" + str);
        System.out.println("加上PIN加密的数据：" + retStr);
    }
}
