如何处理IllegalBlockSizeException:在android中解密的最后一个块不完整

时间:2012-10-31 09:48:59

标签: android exception

我正在使用AES进行加密解密并且工作正常。但是对于安全检查我在文件中做了一些更改。现在,当我正在运行时,它会在它抛出

错误的行上崩溃
javax.crypto.IllegalBlockSizeException: last block incomplete in decryption

。 我已经放了日志和标志,但它没有到达下一行。请建议我如何处理这个异常。我用try catch也没用。代码段是“:

            DataBaseActivity myDbHelper;
        File myFile1 = new File(filing1);   //Date.txt
        FileInputStream fIn = null;
        String  dateDec= null;
        String[] date = null;
        Boolean flag = null;
        Calendar cal1 = null;
        Calendar cal2 = null;

        try {
            fIn = new FileInputStream(myFile1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));

        String aDataRow1 = "";
        String aBuffer1 = "";

        try {
            while ((aDataRow1 = myReader.readLine()) != null) {
                aBuffer1 += aDataRow1;

                myReader.close();
                dateDec = AESencrp.decrypt(aBuffer1); 
                System.out.println("Datedec"+dateDec);
                if(dateDec == ""){
                    flag = false;
                }else {
                    flag = true;
                }
            }
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        }catch (NullPointerException e) {
            e.printStackTrace();
        }

        if(flag == true) {

        try
        {   
                System.out.println("checks1");
                //DataBaseActivity openHelperClass = new DataBaseActivity(this);
                myDbHelper = new DataBaseActivity(this);
              //  myDbHelper = new DataBaseActivity(this);

               System.out.println("checks2");
                try {
                    System.out.println("checks3");
                    myDbHelper.createDataBase();
                    System.out.println("checks4");

            } catch (IOException ioe) {

                throw new Error("Unable to create database");

            }

例外情况在dateDec = AESencrp.decrypt(aBuffer1);

0 个答案:

没有答案