(致版主 - 这是尚未解决的问题的第 3 个相关帖子,现在我发布了所有可能的详细信息,并且在对之前的帖子反馈进行了更改之后,尽管这是一个完整的帖子并且不依赖于之前的 2 个帖子,如果您认为这是重复的,请删除以前的帖子。谢谢)
这是函数的代码
public void decrypt(final InputStream cph_in, final OutputStream out)
{
InputStream in;
try
{
// Bytes read from in will be decrypted
in = new CipherInputStream(cph_in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
//System.out.println(in.read(buf));
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
System.out.println(numRead);
}
//out.close();
}
catch (java.io.IOException e)
{
}
这是控制台输出
the Cell Content : ;Xéü¿Uô{¼9¬ðM
3
the Cell Content : ïB
the Cell Content : þ^[ÊN=—î™ì4´•z&
3
the Cell Content : @ûú!Í?+²uŸK^/?¤
3
the Cell Content : ´ƒôœCëîé V¢%
3
the Cell Content : q^ŽÐâ\Æn2bšcU
3
the Cell Content : ?³j8¥+¤
the Cell Content : R
the Cell Content : 3exÂÊ]ýv>>|Äð
3
the Cell Content : š¾‚ýËe©%Ä»
the Cell Content : Æ´=OöÀ¶+'¸e£Ñßpö
3
the Cell Content : etO„ïŸÞñ?Æü é
the Cell Content : çë
当我将输出流放入 Excel 时,它看起来像这样(注释 124、129,130 等缺失)
*** 问题就在这里..为什么缺少一些数字。
123
125
126
127
128
131
133
135
137
138
139
140
141
143
144
这是对函数的调用
ByteArrayInputStream in = null;
FileOutputStream out = null;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
/*KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); SecretKey key = kgen.generateKey(); byte[] 编码 = key.getEncoded();
IOUtils.write(编码, new FileOutputStream(new File("C:\Users\abc\Desktop\key.txt")));*/
FileInputStream fin = new FileInputStream("C:\key.txt"); DataInputStream din = new DataInputStream(fin);
字节 b[] = 新字节[16];
din.read(b);
InputStream excelResource=new FileInputStream(path);
Workbook rwb=Workbook.getWorkbook(excelResource);
int sheetCount=rwb.getNumberOfSheets();
Sheet rs=rwb.getSheet(0);
int rows=rs.getRows();
int cols=rs.getColumns();
for(int i=0;i<rows;i++){
for(int j=0;j<Col.length;j++){
String theCell_00=rs.getCell(j,i).getContents();
System.out.println("the Cell Content : "+theCell_00);
in = new ByteArrayInputStream(theCell_00.getBytes());
out = new FileOutputStream("c:\\Decrypted.txt");
try
{
//System.out.println(b);
SecretKey key1 = new SecretKeySpec(b, "AES");
// Create encrypter/decrypter class
AESDecrypter encrypter = new AESDecrypter(key1);
encrypter.encrypt(new ByteArrayInputStream(theCell_00.getBytes()),new FileOutputStream("temp.txt"));
// Decrypt
// encrypter.encrypt(,new FileOutputStream("Encrypted.txt"));
encrypter.decrypt(in, out);
我有一种感觉,甚至需要其余的代码,所以我将源代码上传到 http://www.filesavr.com/aesencryption link text (jar但不可执行。要提取) 这就是程序的工作原理
导入 Eclipse 并提供所需的 Apace POI 库后。 您需要将一些数据放入名为 c:\MyExcel.xls 的 excel 文件的第一列中,例如 123 至 144 你需要运行DoEncryption.java 这会将 MyExcel.xls 中的所有数据转换为 c:\workbook.xls 中的 128 位 key AES 加密形式 并创建 c:\key.txt 当工作簿.xls 和 key.txt 存在于 c 目录中并且您运行 DoDecryption.java 时,它将创建 c:\Decrypted.xls,其中包含解密的所有数据,以获取与 MyExcel.xls 相同的原始数据
部分代码甚至未使用,因此要解决问题,请仅遵循此顺序
请大家帮帮我。我指望你了。
最佳答案
您无法将密文(二进制)可靠地存储到单元格中。我怀疑编码弄乱了一些细胞。尝试对密文进行 Base64 或十六进制编码,然后将其存储在单元格中。
如果您必须使用原始二进制文件,请确保您的编码在所有地方都是 Latin-1。 Latin-1 保留二进制序列。
关于java - 输出流中缺少数字(包含完整详细信息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1799421/