public byte[][] createShares(byte[] secret, int shares, int threshold, Random rnd)
{
// some code here
}
我有这种方法,我打算将SSS应用于字节数组文件。 byte [] secret是方法参数,我将在文件中传递每个字节的参数,然后为每个字节应用SSS算法。我还实现了一个如何读取文件并将其转换为字节数组的Java代码。我坚持如何为每个文件字节实现这个SSS算法。 我知道我需要for循环。关键是我想调用我的主要方法这个字节[]秘密,并分配给它的每个字节的文件,但我坚持如何做到这一点。如何循环阵列字节文件
我的方法,这将读取该文件并将其转换为位的阵列是如下:
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;
}
谁能帮助我如何循环的文件的每个字节,然后将其作为参数传递我的createdhares方法?
你应该使用任何这种方法来读取文件(所以你不是重新发明轮子)http://stackoverflow.com/questions/858980/file-to-byte-in-java你也应该更好地解释你的问题。 –
@PacoAbato假设OP试图实现这种:https://en.wikipedia.org/wiki/Shamir's_Secret_Sharing –