2009-11-25 133 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