if (pwd == null) { return; } else { byte[] bytepass = pwd.getBytes(); FileInputStream fs = new FileInputStream(t_file); FileOutputStream out = new FileOutputStream(file); if (fs != null) { int filelen = fs.available(); byte[] real = new byte[filelen]; fs.read(real, 0, filelen);
FileInputStream fs = new FileInputStream(sec_file); FileOutputStream out = new FileOutputStream(zipfile); if (fs != null) { int filelen = fs.available(); byte[] all = new byte[filelen]; fs.read(all, 0, filelen); System.arraycopy(all, 0, bytepass, 0, bytepass.length); byte[] real = new byte[filelen-bytepass.length]; System.arraycopy(all, bytepass.length, real, 0, real.length);
恩 最近在搞这个玩意 不过加密后的zip文件 不能被winRar 识别,只能用自己的程序解密,本来是想做成通用格式的
return;
} else {
byte[] bytepass = pwd.getBytes();
FileInputStream fs = new FileInputStream(t_file);
FileOutputStream out = new FileOutputStream(file);
if (fs != null) {
int filelen = fs.available();
byte[] real = new byte[filelen];
fs.read(real, 0, filelen);
SecretKeyFactory keyfac = SecretKeyFactory.getInstance("DES");
byte[] keydata;
keydata = bytepass;
DESKeySpec keySp = new DESKeySpec(keydata);
Key key = keyfac.generateSecret(keySp);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(real);
byte[] all = new byte[cipherText.length + bytepass.length];
System.arraycopy(bytepass, 0, all, 0, bytepass.length);
System.arraycopy(cipherText,0, all, bytepass.length, cipherText.length); out.write(all);
}
fs.close();
out.close();
return;
}
else {
byte[] bytepass = pwd.getBytes();
FileInputStream fs = new FileInputStream(sec_file);
FileOutputStream out = new FileOutputStream(zipfile);
if (fs != null) {
int filelen = fs.available();
byte[] all = new byte[filelen];
fs.read(all, 0, filelen);
System.arraycopy(all, 0, bytepass, 0, bytepass.length); byte[] real = new byte[filelen-bytepass.length];
System.arraycopy(all, bytepass.length, real, 0, real.length);
SecretKeyFactory keyfac = SecretKeyFactory.getInstance("DES");
byte[] keydata;
keydata = bytepass;
DESKeySpec keySp = new DESKeySpec(keydata);
Key key = keyfac.generateSecret(keySp);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(real);
out.write(cipherText);
}
fs.close();
out.close();