2009-11-25 66 views
0

(对于版主 - 这是尚未解决的问题的第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中提出的OutputStream它看起来像这样(注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 [] encoded = key.getEncoded();

IOUtils.write(编码,新的FileOutputStream中(新文件( “C:\用户\ ABC \桌面\ key.txt”))); */

的FileInputStream鳍=新的FileInputStream(“C:\ key.txt“); DataInputStream din = new DataInputStream(fin);

byte b [] = new byte [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 (要提取罐中,但不能执行。)上传的源代码的感觉 这是怎样的程序工作

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

一些代码的部分甚至不使用,以便解决该问题,请按照此顺序仅

家伙请帮助我出去了。 m依靠你。

回答

1

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

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

+0

你能告诉我如何实现 – rover12 2009-11-25 20:19:32

相关问题