[英]Reading from an encrypted file into a declared string variable
我有一个加密的文件,使用这个问题的引用完成了。我已经加密了文件。现在我的问题是当试图读取内容时,正在从返回的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();
}
}
任何指针为什么不能正确获取加密文件的内容?
在解密字节数组的那一行,它仍然是空的。 您尚未读入文件。 您必须切换操作。
byte[] filebyte = new byte[length]
fis.read(filebyte);
byte[] tmpTxt = mDecipher.doFinal(filebyte);
fis.close();
String plaintxt = new String(tmpTxt, "UTF-8");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.