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;
}
ファイルの各バイトをループし、それを引数として createshares メソッドに渡す方法を教えてもらえますか?