public byte[][] createShares(byte[] secret, int shares, int threshold, Random rnd)
{
// some code here
}
I have this method and i am going to apply SSS for file of byte array . byte [] secret is method parameter where i am going to pass as argument each byte of the file and then apply for each byte the SSS algorithm. I have also implemented a java code of how to read the file and then convert it to a byte array. I am stuck of how to implement this SSS algorithm for each byte of files. I know i need a for loop for that . The point is i want to call to my main method this byte [] secret and assign to it each byte of the file but i am stuck of how to do it .
My method which will read the file and convert it to the array of bit is as below:
public byte[] readFile(File fileName) throws IOException {
InputStream is = new FileInputStream(fileName);
// Get the size of the file
long length = fileName.length();
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
throw new IOException("Could not completely read file " + fileName.getName() + " as it is too long (" + length + " bytes, max supported " + Integer.MAX_VALUE + ")");
}
// Create the byte array to hold the data
byte[] secret = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < secret.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < secret.length) {
throw new IOException("Could not completely read file " + fileName.getName());
}
// Close the input stream and return bytes
is.close();
return secret;
}
Can anyone help me how to loop for each byte of the file and then pass it as the argument to my createshares method ?