/*
OTP4U 0.8.0 - One Time Pad for you
Copyright (C) 2003 Pierre Blanc
Pierre Blanc: blanc_teutoburgo@yahoo.it
http://www.teutoburgo.tk
http://it.geocities.com/teutoburgo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or go to http://www.gnu.org/copyleft/gpl.html
*/
package tk.teutoburgo.otp4u.io;
import tk.teutoburgo.otp4u.constants.*;
import tk.teutoburgo.otp4u.util.*;
import java.io.*;
public class Io{
public static final String SEPARATOR
=Constants.
SEPARATOR,
PUBLIC_KEY_FILE=Constants.PUBLIC_KEY_FILE,
RANDOM_KEY_FILE=Constants.RANDOM_KEY_FILE,
KEY_SMALL = Constants.KEY_SMALL,
PLAIN= Constants.PLAIN, CIPHER=Constants.CIPHER,
RANDOM_KEY=Constants.RANDOM_KEY, PUBLIC_KEY=Constants.PUBLIC_KEY,
ENTROPY=Constants.ENTROPY;
boolean isGUI=false;
MessagesPrinter mp;
public Io(){
mp = new MessagesPrinter();
}
public Io
(String home,
boolean isGUI
){
OTP4U_HOME=home;
this.isGUI=isGUI;
mp = new MessagesPrinter(isGUI);
//System.out.println("\n---- honme io "+OTP4U_HOME);
}
byte[][] arrays=new byte[2][];
byte[] fileToXOR=null;
//mp.sPrintLog("home "+OTP4U_HOME );
fileToXOR = this.readFile(pathName);
byte[] randomKeyBytes = this.readFile(OTP4U_HOME + RANDOM_KEY +
RANDOM_KEY_FILE);
arrays[0]=fileToXOR;
arrays[1]=randomKeyBytes;
return arrays;
}
int index=pathName.lastIndexOf(Constants.SEPARATOR);
if (index!=-1)
pathName = pathName.substring(index+1);
return pathName;
}
long fLength = f.length();
byte[] file = new byte[(int) fLength];
fis.read(file);
return file;
}
/**
* Reads the array pubKey containig the files in the entropySource directory
* @param pathName The pathname
* @return The array pubKey
*/
// mp.sPrintLog("read "+pathName);
File[] list
= f.
listFiles();
int len = list.length, i = 0, j = 0;
long fLength = 0;
byte[][] mngs = new byte[len][];
mp.sPrintLog("Reading "+len+" entropy source file(s):");
for (i = 0; i < len; i++) {
mp.sPrintLog(list[i].toString());
if (list[i].isFile()) {
fLength = list[i].length();
mngs[i] = new byte[(int) fLength];
j++;
}
}
mp.sPrintLog("");
byte[][] pubKey = new byte[j][];
for (i = 0; i < j; i++) {
pubKey[i] = mngs[i];
}
return pubKey;
}
fos.write(bytes);
mp.sPrintLog("Written "+name);
}
}