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");