0

(致版主-这是尚未解决的问题的第三个相关帖子,现在我发布所有可能的详细信息,并且在对以前的帖子反馈进行更改之后,虽然这是一个完整的帖子并且不依赖于之前的 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 密钥 = kgen.generateKey(); byte[] 编码 = key.getEncoded();

IOUtils.write(encoded, 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 链接文本 (jar 但不可执行。要提取)这就是节目作品

导入 Eclipse 并提供所需的 Apace POI 库后。您需要将一些数据放在名为 c:\MyExcel.xls 的 Excel 文件的第一列中,例如 123 到 144 您需要运行 DoEncryption.java 这会将 MyExcel.xls 中的所有数据转换为 c 中的 128 位密钥 AES 加密形式:\workbook.xls 并创建 c:\key.txt 当 c 目录中存在 workbook.xls 和 key.txt 并且您运行 DoDecryption.java 时,它将创建 c:\Decrypted.xls 包含所有解密的数据以获得原始数据我的Excel.xls

有些部分代码甚至没有使用,所以解决问题请按照这个顺序

伙计们请帮帮我。我指望你。

4

1 回答 1

1

您无法将密文(二进制)可靠地存储到单元格中。我怀疑编码弄乱了一些单元格。尝试对密文进行 base64 或十六进制编码,然后将其存储在单元格中。

如果您必须使用原始二进制文件,请确保您的编码在任何地方都是 Latin-1。Latin-1 保留二进制序列。

于 2009-11-25T19:56:12.823 回答