package com.keystar.plane.inspection.utils;

import com.keystar.plane.inspection.bo.Location;
import org.apache.commons.codec.binary.Base64;

import javax.crypto.Cipher;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.interfaces .RSAPublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utils {


    /**
     *  RSA加密
     **/
    public static String encrypt(String str, String publicKey ) throws Exception {
        //base64编码的公钥
        byte[] decoded = Base64.decodeBase64(publicKey);
        RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
        //RSA加密
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
        return Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8)));

    }

    /**
     *  截取字符串中数字转成double
     **/
    public static Double getNumber(String str){
        String[] s = str.split(" ");
        return Double.parseDouble(s[0]);
    }


    /**
     *  获取光伏区域坐标
     **/
    public static List<Location> getAllLocation(){
        Location location = new Location();
//        location.setLat();
//        location.setLon();
        return null;
    }
}
