In the ZIP file password protection

Hi all

I spoke of the code to create a zip file. Its working fine. Now, I want to add the password in this zip file. Can someone help me in there to achieve?

Zip code:
------------
import java.util.zip.*;
import java.io.*;
public class UTLZip
{
 public static void compressFile(String infilename, String outfilename)
 throws IOException
 {
  try
    {
     FileOutputStream fout = new FileOutputStream(outfilename);
     ZipOutputStream zout = new ZipOutputStream(fout);
     ZipEntry ze = new ZipEntry((new File(infilename)).getName());
     try 
       {
        FileInputStream fin = new FileInputStream(infilename);
        zout.putNextEntry(ze);
        copy(fin, zout);
        zout.closeEntry();
        fin.close();
       }
     catch (IOException ie)
     {
      System.out.println("IO Exception occurred: " + ie);
     }
     zout.close();
    }
  catch(Exception e)
    {
     System.out.println("Exception occurred: " + e);
    }
 }
  
 public static void copy(InputStream in, OutputStream out) 
      throws IOException
 { 
  byte[] buffer = new byte[4096];
  while (true) {
    int bytesRead = in.read(buffer);
    if (bytesRead == -1) break;
    out.write(buffer, 0, bytesRead);
  }
 }     
}
 
----------------------------------------------------------------

create or replace
PACKAGE               "SSSL_FILE_ZIP" 
IS
   PROCEDURE compressFile (p_in_file IN VARCHAR2, p_out_file IN VARCHAR2)
   AS
      LANGUAGE JAVA
         NAME 'UTLZip.compressFile(java.lang.String,
                   java.lang.String)';
END;

 
 
Thanks in advance
San,

I have not tested the code with large files, it was just a quick hack.
Try to change the encrypt with this function

  function encrypt( p_pw varchar2, p_src blob )
  return blob
  is
    t_salt raw(16);
    t_key  raw(32);
    t_pw raw(32767) := utl_raw.cast_to_raw( p_pw );
    t_key_bits pls_integer := 256;
    t_key_length pls_integer := t_key_bits / 8 * 2 + 2;
    t_cnt pls_integer := 1000;
    t_keys raw(32767);
    t_sum raw(32767);
    t_mac raw(20);
    t_iv raw(16);
    t_block raw(16);
    t_len pls_integer;
    t_rv blob;
    t_tmp blob;
  begin
    t_salt := dbms_crypto.randombytes( t_key_bits / 16 );
    for i in 1 .. ceil( t_key_length / 20 )
    loop
      t_mac := dbms_crypto.mac( utl_raw.concat( t_salt, to_char( i, 'fm0xxxxxxx' ) ), dbms_crypto.HMAC_SH1, t_pw );
      t_sum := t_mac;
      for j in 1 .. t_cnt - 1
      loop
        t_mac := dbms_crypto.mac( t_mac, dbms_crypto.HMAC_SH1, t_pw );
        t_sum := utl_raw.bit_xor( t_mac, t_sum );
      end loop;
      t_keys := utl_raw.concat( t_keys, t_sum );
    end loop;
    t_keys := utl_raw.substr( t_keys, 1, t_key_length );
    t_key := utl_raw.substr( t_keys, 1, t_key_bits / 8 );
    t_rv := utl_raw.concat( t_salt, utl_raw.substr( t_keys, -2, 2 ) );
--
    for i in 0 .. trunc( ( dbms_lob.getlength( p_src ) - 1 ) / 16 )
    loop
      t_block := dbms_lob.substr( p_src, 16, i * 16 + 1 );
      t_len := utl_raw.length( t_block );
      if t_len < 16
      then
        t_block := utl_raw.concat( t_block, utl_raw.copies( '00', 16 - t_len ) );
      end if;
      t_iv := utl_raw.reverse( to_char( i + 1, 'fm000000000000000000000000000000x' ) );
      dbms_lob.writeappend( t_rv, t_len, dbms_crypto.encrypt( t_block, dbms_crypto.ENCRYPT_AES256 + dbms_crypto.CHAIN_CFB + dbms_crypto.PAD_NONE, t_key, t_iv ) );
    end loop;
--
    dbms_lob.createtemporary( t_tmp, true );
    dbms_lob.copy( t_tmp, t_rv, dbms_lob.getlength( p_src ), 1, t_key_bits / 16 + 2 + 1 );
    t_mac := dbms_crypto.mac( t_tmp, dbms_crypto.HMAC_SH1, utl_raw.substr( t_keys, 1 + t_key_bits / 8, t_key_bits / 8 ) );
    dbms_lob.writeappend( t_rv, 10, t_mac );
    dbms_lob.freetemporary( t_tmp );
    return t_rv;
  end;

Tags: Database

Similar Questions

Maybe you are looking for

  • missing multimedia controller driver?

    I have a laptop hp pavilion dv5-1221tx... recently I upgraded my computer laptop windows vista home edition premium---> windows 7 Ultimate edition... the problem is that, although I have downloaded all the drivers supplied by hp via internet, but sti

  • Retriving former opus after wipe system

    I had recently wiped my computer because if a bad virus and now I canoe get my origanal op back (vista) system I put hp about it and I was wondering is there any way I can recover Vista because xp is really not for me.

  • Printer Migration (XP to Win 7)

    Hello I have a stand alone PC XP with a printer directly connected to it.I have have just branch PC Win 7 and want to migrate the printer (and settings) for her to the XP machine. I know that MS has a for Win 7 for Win 7 migration tool, but how do I

  • BlackBerry Z10 please help stop: find one in your city

    Hello Since 3 days I have a problem on my Z10 I always get a notification saying: find one in your city and also that sends me to a site of meetings (xapush.com) I also mention announcement by barcode This request was withdrawn 2 days ago, but I stil

  • ONS 15454 presents itself as 'unknown' after power failure

    We had a power failure that also landed an ONS 15454 in a remote installation. To restore power and power on the device, it appears in the CTC under gray with "Uknown2" as the name. I had someone reinsert the card of STC, but sometimes still unknown.