微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

线程“main”中的异常 java.lang.NoSuchMethodError: lw.bouncycastle.openpgp.PGPEncryptedData lw.bouncycastle.openpgp.PGPEncryptedDataList.get(int)

如何解决线程“main”中的异常 java.lang.NoSuchMethodError: lw.bouncycastle.openpgp.PGPEncryptedData lw.bouncycastle.openpgp.PGPEncryptedDataList.get(int)

请帮帮我。我在线程“main”java.lang.NoSuchMethodError 中收到错误消息异常

请帮助我,因为这是我在工作领域的第一个项目

public static void decrypt() {
        logger.info("Start decrypt");
        PGPLib pgp = new PGPLib();
        String privateKeyFile = prop.getProperty("app.privatekey");
        String privateKeyPass = prop.getProperty("app.passphrase");
        String publicKeyFile = prop.getProperty("app.publickey");
        String[] pass = new String[0];
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(privateKeyPass),StandardCharsets.UTF_8));
             CSVReader csvReader = new CSVReaderBuilder(reader).build()){
            List<String[]> records= csvReader.readAll();
            pass= records.get(0);
        } catch (IOException e) {
            e.printstacktrace();
        }

        if(!checkConfig(privateKeyFile,publicKeyFile,privateKeyPass))
            return;

        File dir = new File(prop.getProperty("app.pathIn"));

        if (!dir.exists()) {
            logger.severe("Folder IN not found");
            return;
        }

        String[] fileList = dir.list();

        if (fileList.length==0) {
            logger.warning("nothing file to decrypt");
            return;
        }

        // verify and extract the signed content
        boolean status= false;

        for (String name:fileList) {
            File fileName = new File(name);

            if (fileName.getName().contains(".asc") || fileName.getName().contains(".gpg") || fileName.getName().contains(".pub")) {

                SignatureCheckResult signatureCheck = null;
                try {
                    logger.info("Starting decrypt file "+ name);
                    String[] outname= name.split("\\.");
                    signatureCheck = pgp.decryptAndVerify(prop.getProperty("app.pathIn")+name,privateKeyFile,pass[0],prop.getProperty("app.pathDecrypt")+outname[0]+".txt");

                    logger.info("File "+name+" decrypted.");
                    try {
                        Files.move(Paths.get(prop.getProperty("app.pathIn") + name),Paths.get(prop.getProperty("app.pathBackup") + name),StandardcopyOption.REPLACE_EXISTING);
                        logger.info("File " + name + " moved");
                    }catch (IOException e){
                        logger.warning(e.toString());
                        logger.warning("Failed to move file.");
                    }

                } catch (NoSuchFileException | FileNotFoundException | PGPException e) {
                    logger.warning(e.toString());
                    System.exit(0);
                } catch (IOException e) {
                    logger.warning(e.toString());
                    return;
                }

                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
                    status= true;
                    logger.info("The signature is valid");
                } else if (signatureCheck == SignatureCheckResult.Signaturebroken) {
                    status= true;
                    logger.warning("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
                    status= true;
                    logger.warning("Signature not matching provided public key (the message is from another sender)");
                } else {
                    status= false;
                    logger.warning("No signature found in message");
                }
            }else{
                logger.warning("Please check input file.");
            }
        }

        if (status) {
            convert();
        }
    }

错误信息

Exception in thread "main" java.lang.NoSuchMethodError: 'lw.bouncycastle.openpgp.PGPEncryptedData lw.bouncycastle.openpgp.PGPEncryptedDataList.get(int)'
    at com.didisoft.pgp.PGPLib.a(UnkNown Source)
    at com.didisoft.pgp.PGPLib.decryptAndVerify(UnkNown Source)
    at com.didisoft.pgp.PGPLib.decryptAndVerify(UnkNown Source)
    at converter.ConverterMT940.decrypt(ConverterMT940.java:436)
    at converter.ConverterMT940.main(ConverterMT940.java:106)
C:\Users\wangu\AppData\Local\NetBeans\Cache\12.2\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\wangu\AppData\Local\NetBeans\Cache\12.2\executor-snippets\run.xml:68: Java returned: 1enter code here

我的源代码

import org.joda.time.LocalDate;
//import java.time.LocalDate;
//import java.time.temporal.ChronoUnit;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import com.didisoft.pgp.PGPException;
import com.didisoft.pgp.PGPLib;
import com.didisoft.pgp.SignatureCheckResult;

import javax.swing.*;

public class ConverterMT940 {
    public JPanel panel;
    public jpasswordfield passphraseText;
    public JButton submit;

    private static Logger logger;
    private static String passphrase;
    private static JFrame frame;

    private static Properties prop;
    private static String configFile;

    private ConverterMT940(){
        submit.setText("Decrypt");

        Action action = new AbstractAction()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                passphrase= new String(passphraseText.getpassword());
                if(!passphrase.equals("")) {
                    frame.setVisible(false);
                    decrypt();
                }
            }
        };
        passphraseText.addActionListener(action);

//        submit.getInputMap().put(Keystroke.getKeystroke("ENTER"));
        submit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                passphrase= new String(passphraseText.getpassword());
                if(!passphrase.equals("")) {
                    frame.setVisible(false);
                    decrypt();
                }
//                System.out.println(passphrase);
            }
        });
    }

    public static void main(String[] args) throws IOException {
        File folderLog = new File("Log");
        if (!folderLog.exists()) {
            folderLog.mkdir();
        }

        prop = new Properties();
        configFile= "app.config";

        InputStream is= null;
        try {
            is = new FileInputStream(configFile);
            prop.load(is);
        } catch (IOException e) {
            e.printstacktrace();
        }

        FileHandler fh = new FileHandler("Log/ConverterLog.log",true);
        logger = Logger.getLogger("Log");
        logger.addHandler(fh);
        logger.setLevel(Level.ALL);
        SimpleFormatter formatter = new SimpleFormatter();
        fh.setFormatter(formatter);

        if(!checkFolder()) {
            System.exit(0);
        }

        decrypt();
//        convert();
    }

    private static boolean checkFolder(){
        File folderDecrypt= new File(prop.getProperty("app.pathDecrypt"));
        File folderIN= new File(prop.getProperty("app.pathIn"));
        File folderBackup= new File(prop.getProperty("app.pathBackup"));
        File folderMT= new File(prop.getProperty("app.pathMt"));

        boolean status= true;

        if (!folderDecrypt.exists()){
            logger.severe("Folder DECRYPT not found.");
            status= false;
        }

        if(!folderBackup.exists()){
            logger.severe("Folder BACKUP not found.");
            status= false;
        }

        if(!folderIN.exists()){
            logger.severe("Folder IN not found.");
            status= false;
        }

        if(!folderMT.exists()){
            logger.severe("Folder MT not found.");
            status= false;
        }
        return status;
    }

    private static String getCurrency(String code){
        ArrayList<String[]> currency= new ArrayList<>();
        currency.add(new String[]{"AUD","036"});
        currency.add(new String[]{"NZD","554"});
        currency.add(new String[]{"EUR","978"});
        currency.add(new String[]{"GBP","826"});
        currency.add(new String[]{"JPY","392"});
        currency.add(new String[]{"SGD","702"});
        currency.add(new String[]{"HKD","344"});
        currency.add(new String[]{"CAD","124"});
        currency.add(new String[]{"CHF","756"});
        currency.add(new String[]{"IDR","360"});

        for (String[] data:currency) {
            if(data[1].equals(code)){
                logger.info("Currency found");
                return data[0];
            }
        }
        logger.warning("Currenct not found");
        return "";
    }

    private static String dateConverter(String stringDate){
        String tempDate= "";
        for(int i=0; i<stringDate.length(); i++){
            tempDate= tempDate+stringDate.charat(i);
            if (i==3)
                tempDate= tempDate+"-";

            if (i==5)
                tempDate= tempDate+"-";
//            System.out.println(stringDate.charat(i));
        }
//        System.out.println(tempDate);

        return tempDate;
    }

    private static boolean checkConfig(String privatekey,String publickey,String passphrase){
        logger.info("Reading configuration file.");
        boolean status= true;

        if (privatekey==null){
            status=false;
            logger.warning("Private key not found,");
        }

        if (publickey==null){
            status=false;
            logger.warning("Public key not found.");
        }

        if (passphrase==null){
            status=false;
            logger.warning("Passphrase null");
        }

        return status;
    }

    public static void convert() {
        String fileMnemonic = "MNEMONIC/MT9xx Mnemonic - Agung.csv";

        ArrayList<String> codeName1 = new ArrayList<>();
        List<List<String>> dataFileMnemonic = new ArrayList<>();

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(ConverterMT940.class.getResourceAsstream(fileMnemonic)));
             CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).build()) {
            logger.info("Start mapping file mnemonic");
            List<String[]> records = csvReader.readAll();
            for (String[] record : records) {
                codeName1.add(record[0]);
                dataFileMnemonic.add(Arrays.asList(record));
            }
            logger.info("Mapping file mnemonic done");
        } catch (RuntimeException | IOException e) {
//                e.printstacktrace();
            logger.severe(e.toString());
            logger.severe("File mnemonic not found");
            System.exit(0);
        }

        File dir = new File(prop.getProperty("app.pathDecrypt"));
        if (!dir.exists()) {
            logger.severe("Folder DECRYPT not found");
            System.exit(0);
        }
        String[] fileList = dir.list();
        if (fileList.length==0){
            logger.warning("nothing file to convert");
        }

        for(String name:fileList) {
            String fileIn = prop.getProperty("app.pathDecrypt") + name;
            String[] outName= name.split("\\.");
            String fileOut = prop.getProperty("app.pathMt")+outName[0]+"_Converted.txt";

            File file = new File(fileIn);
            String fileInName = file.getName();
//        System.out.println(fileInName);

            boolean status = false;
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileIn),StandardCharsets.UTF_8));
                 CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).build();
                 OutputStream outputStream = new FileOutputStream(fileOut);
                 Writer writer = new OutputStreamWriter(outputStream);
                 CSVWriter csvWriter = new CSVWriter(writer,'\u0000',"");
            ) {
                logger.info("Starting convert file "+name);

                String[] fileName = fileInName.split("_");
                String[] date = fileName[2].split("\\.");

                String dateBeforeString = "2020-01-01";
                String dateAfterString= dateConverter(date[0]);
                LocalDate dateBefore = LocalDate.parse(dateBeforeString);
                LocalDate dateAfter= LocalDate.parse(dateAfterString);
                long days = Days.daysBetween(dateBefore,dateAfter).getDays()+1;

                List<String[]> records = csvReader.readAll();

                boolean convertStatus= true;
//                Checking date
                for(String[] record:records){
                    String[] trxDate= record[0].split(" ");
                    if (!date[0].equals(trxDate[0]) && convertStatus) {
                        logger.severe("Transaction date file "+name+" not same");
                        logger.severe("Failed converting file "+ name);
//                        System.exit(0);
                        convertStatus= false;
                    }

                    if (record.length!=14 && convertStatus){
                        logger.severe("Error file structure "+name);
                        logger.severe("Failed converting file "+name);
//                        System.exit(0);
                        convertStatus= false;
                    }
                }

                if(convertStatus) {

                    List<String[]> data = new ArrayList<String[]>();
                    data.add(new String[]{"\u0001{1:F01BANK DANAMON}{2:" + fileName[0] + "}{4:"+"\r\n"});
                    data.add(new String[]{":20:" + date[0].substring(2,8)+"\r\n"});
                    data.add(new String[]{":25:" + fileName[1]+"\r\n"});
                    data.add(new String[]{":28C:" + String.format("%05d",Integer.parseInt(String.valueOf(days)))+"\r\n"});

//                    csvWriter.writeNext(new String[]{"\u0001{1:F01BANK DANAMON}{2:" + fileName[0] + "}{4:"+"\r\n"});
//                    csvWriter.writeNext(new String[]{":20:" + date[0].substring(2,8)+"\r\n"});
//                    csvWriter.writeNext(new String[]{":25:" + fileName[1]+"\r\n"});
//                    csvWriter.writeNext(new String[]{":28C:" + String.format("%05d",Integer.parseInt(String.valueOf(days)))+"\r\n"});

                    String[] firstElement = records.get(0);
//            System.out.println(firstElement[1]);
                    String currency = getCurrency(firstElement[7]);
                    if (currency == null) {
                        logger.warning("Currency mot found "+ name);
                    }

                    Double tempAmount= Double.parseDouble(firstElement[12]);
                    String amount= df.format(tempAmount).replace(".",",");
                    if (currency.equals("IDR") || currency.equals("JPY")) {
                        amount = getAmount(firstElement[12]);
                    }

                    data.add(new String[]{":60F:" + firstElement[9] + date[0].substring(2,8) + currency + amount+"\r\n"});
//                    csvWriter.writeNext(new String[]{":60F:" + firstElement[9] + date[0].substring(2,8) + currency + String.format("%015.2f",//                            Float.parseFloat(firstElement[12])).replace(".",")+"\r\n"});

                    for (String[] record : records) {
                        String[] code = record[4].split(":");
                        int indexCodeName = codeName1.indexOf(code[0]);
                        List<String> dataMnemonic = dataFileMnemonic.get(indexCodeName);
                        String codeName = dataMnemonic.get(1);

                        tempAmount= Double.parseDouble(record[8]);
                        amount = df.format(tempAmount).replace(".",");
                        if (currency.equals("IDR") || currency.equals("JPY")) {
                            amount = getAmount(record[8]);
                        }

                        String[] dateTrx= record[0].split(" ");

                        data.add(new String[]{":61:" + dateTrx[0].substring(2,8) + record[9] +
                                amount + codeName + record[11]+"\r\n"});
                        data.add(new String[]{":86:" + record[10]+"\r\n"});
//                        csvWriter.writeNext(new String[]{":61:" + dateTrx[0].substring(2,8) + record[9] +
//                                amount + codeName + record[11]+"\r\n"});
//                        csvWriter.writeNext(new String[]{":86:" + record[10]+"\r\n"});

                    }

                    String[] lastElement = records.get(records.size() - 1);
                    currency = getCurrency(lastElement[7]);

                    tempAmount= Double.parseDouble(lastElement[13]);
                    amount= df.format(tempAmount).replace(".",");
                    if (currency.equals("IDR") || currency.equals("JPY")) {
                        amount = getAmount(lastElement[13]);
                    }

                    data.add(new String[]{":62F:" + lastElement[9] + date[0].substring(2,8) + currency + amount+"\r\n"});
                    data.add(new String[]{"-}"+"\u0003\r\n"});
//                    csvWriter.writeNext(new String[]{":62F:" + lastElement[9] + date[0].substring(2,//                            Float.parseFloat(lastElement[13])).replace(".",")+"\r\n"});
//                    csvWriter.writeNext(new String[]{"-}"+"\u0003\r\n"});

                    for (int i=0; i<2; i++){
                        data.add(new String[]{"\r\n"});
//                        csvWriter.writeNext(new String[]{"\r\n"});
                    }

//            System.out.println("File converted");
                    csvWriter.writeall(data,true);
                    csvWriter.flush();
                    logger.info("File " + name + " converted");
                    status = true;
                }
            } catch (IOException e) {
                e.printstacktrace();
                logger.severe(e.toString());
                logger.severe("Failed converting file "+name);
                status= false;
                System.exit(0);
            }


            if(status) {
                try {
//            Move In file to History
                    Files.move(Paths.get(prop.getProperty("app.pathDecrypt") + name),Paths.get(prop.getProperty("app.pathBackup")+ name),StandardcopyOption.REPLACE_EXISTING);
                    logger.info("File " + name + " moved to BACKUP");
                }catch (IOException e){
                    logger.severe(e.toString());
                    logger.severe("Failed to move file");
                    System.exit(0);
                }
            }
        }
    }

    private static String getAmount(String record) {
        Double tempAmount = Double.parseDouble(record);
        String[] tempDecimal = df.format(Math.round(tempAmount)).split("\\.");
        return tempDecimal[0];
    }

    private static DecimalFormat df = new DecimalFormat("000000000000.00");

    public static void decrypt() {
        logger.info("Start decrypt");
        // initialize the library instance
        PGPLib pgp = new PGPLib();

        String privateKeyFile = prop.getProperty("app.privatekey");
        String privateKeyPass = prop.getProperty("app.passphrase");
//        String privateKeyPass= passphrase;
        String publicKeyFile = prop.getProperty("app.publickey");
        String[] pass = new String[0];
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(privateKeyPass),StandardCharsets.UTF_8));
             CSVReader csvReader = new CSVReaderBuilder(reader).build()){
            List<String[]> records= csvReader.readAll();
            pass= records.get(0);
        }catch (IOException e) {
            e.printstacktrace();
        }

        if(!checkConfig(privateKeyFile,privateKeyPass))
            return;

        File dir = new File(prop.getProperty("app.pathIn"));
        if (!dir.exists()) {
            logger.severe("Folder IN not found");
//            System.exit(0);
            return;
        }
        String[] fileList = dir.list();
        if (fileList.length==0){
            logger.warning("nothing file to decrypt");
            return;
        }
        // verify and extract the signed content
        boolean status= false;

        for (String name:fileList) {
            File fileName = new File(name);

            if (fileName.getName().contains(".asc") || fileName.getName().contains(".gpg") || fileName.getName().contains(".pub")) {

                SignatureCheckResult signatureCheck = null;
                try {
                    logger.info("Starting decrypt file "+ name);
                    String[] outname= name.split("\\.");
                    signatureCheck = pgp.decryptAndVerify(prop.getProperty("app.pathIn")+name,prop.getProperty("app.pathDecrypt")+outname[0]+".txt");

                    logger.info("File "+name+" decrypted.");

//            Move In file to History
                    try {
                        Files.move(Paths.get(prop.getProperty("app.pathIn") + name),StandardcopyOption.REPLACE_EXISTING);
                        logger.info("File " + name + " moved");
                    }catch (IOException e){
                        logger.warning(e.toString());
                        logger.warning("Failed to move file.");
                    }

                } catch (NoSuchFileException | FileNotFoundException | PGPException e) {
//            e.printstacktrace();
                    logger.warning(e.toString());
                    System.exit(0);
//                    return;
                } catch (IOException e) {
                    logger.warning(e.toString());
//                    System.exit(0);
                    return;
//            e.printstacktrace();
                }

                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
                    status= true;
//                    System.out.println("The signature is valid.");
                    logger.info("The signature is valid");
                } else if (signatureCheck == SignatureCheckResult.Signaturebroken) {
                    status= true;
//                    System.out.println("Message corrupted or signature forged");
                    logger.warning("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
                    status= true;
//                    System.out.println("Signature not matching provided public key (the message is from another sender)");
                    logger.warning("Signature not matching provided public key (the message is from another sender)");
                } else {
                    status= false;
//                    System.out.println("No signature found in message");
                    logger.warning("No signature found in message");
                }
            }else{
                logger.warning("Please check input file.");
            }
        }

        if (status) {
            convert();
        }
//        System.exit(0);
    }
}

这是日志

2021 年 4 月 9 日下午 2:58:11 转换器。转换器MT940 解密

信息:开始解密

2021 年 4 月 9 日下午 2:58:12 转换器.ConverterMT940 checkConfig

信息:读取配置文件

2021 年 4 月 9 日下午 2:58:12 转换器。转换器MT940 解密

信息:开始解密文件 KAI001_007700096295_20200722.txt.gpg

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?