For my java class, part of my project involves getting a encryption key length from the user and rounding that up to the nearest multiple of 1024. The length is passed as a long. In my method I get the long and I get the file path to write to. In examples I've seen this implementation:
try (FileOutputStream out = new FileOutputStream(file)) {
byte[] bytes = new byte[1024];
new SecureRandom().nextBytes(bytes);
out.write(bytes);
}
But where and how do I implement my long variable? I can't put a long in byte[long]. I know I need to used the SecureRandom().nextBytes() according to my professor. Any help would be greatly appreciated because this part has been driving me crazy.
Here is what I have so far but I can't help but think this isn't the way my professor wants it done...
public void oneKeyGenerator(String keyPath, long keyLength) {
final long CONST_MULTIPLE = 1024;
try {
FileOutputStream out = new FileOutputStream(keyPath);
byte[] bytes = new byte[1024];
for(long x = 0; x < keyLength/CONST_MULTIPLE; x++) {
new SecureRandom().nextBytes(bytes);
out.write(bytes);
}
} catch(IOException e){
gui.fileException(e.getMessage());
}
}