Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从加密文件读入声明的字符串变量_Java_Android_Encryption_Fileinputstream - Fatal编程技术网

Java 从加密文件读入声明的字符串变量

Java 从加密文件读入声明的字符串变量,java,android,encryption,fileinputstream,Java,Android,Encryption,Fileinputstream,我有一个加密文件,它是使用中的引用完成的。我对该文件进行了加密。现在我的问题是,当尝试读取内容时,我从返回的read()中得到一个空字符串。下面是我的调用方法和将加密文本解密为字符串变量的方法 调用方法: File encryptedCFG = new File(homeDir + "/" + folder_name + "/twCGF.txt"); dc.ReadEncryptedFile(encryptedCFG); public void ReadEncryptedFile(File

我有一个加密文件,它是使用中的引用完成的。我对该文件进行了加密。现在我的问题是,当尝试读取内容时,我从返回的
read()
中得到一个空字符串。下面是我的调用方法和将加密文本解密为字符串变量的方法

调用方法:

File encryptedCFG = new File(homeDir + "/" + folder_name + "/twCGF.txt");
dc.ReadEncryptedFile(encryptedCFG); 
public void ReadEncryptedFile(File deInFile) {
        try {
            FileInputStream fis = new FileInputStream(deInFile);
            int length = (int) deInFile.length();
            byte[] filebyte = new byte[length]
            // Decrypt the byte contents from the file using the cipher setup
            byte[] tmpTxT = mDecipher.doFinal(filebyte);
            fis.read(tmpTxT);
            fis.close();

         // Read into a string since we got the contents
         String plaintxt = new String(tmpTxt, "UTF-8");

         } catch (Exception e) {
            e.printStackTrace();
        }
    }
方法:

File encryptedCFG = new File(homeDir + "/" + folder_name + "/twCGF.txt");
dc.ReadEncryptedFile(encryptedCFG); 
public void ReadEncryptedFile(File deInFile) {
        try {
            FileInputStream fis = new FileInputStream(deInFile);
            int length = (int) deInFile.length();
            byte[] filebyte = new byte[length]
            // Decrypt the byte contents from the file using the cipher setup
            byte[] tmpTxT = mDecipher.doFinal(filebyte);
            fis.read(tmpTxT);
            fis.close();

         // Read into a string since we got the contents
         String plaintxt = new String(tmpTxt, "UTF-8");

         } catch (Exception e) {
            e.printStackTrace();
        }
    }

有任何指针说明我为什么不能正确获取加密文件的内容吗?

在解密字节数组的那一行,它仍然是空的。您尚未读入该文件。你必须切换操作

byte[] filebyte = new byte[length]
fis.read(filebyte);
byte[] tmpTxt = mDecipher.doFinal(filebyte);
fis.close();

String plaintxt = new String(tmpTxt, "UTF-8");