mirror of https://github.com/M66B/FairEmail.git
Read buffer helper
This commit is contained in:
parent
1c0101b43e
commit
571ed13f0b
|
@ -717,10 +717,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
else {
|
||||
byte[] salt = new byte[16];
|
||||
byte[] prefix = new byte[16];
|
||||
if (raw.read(salt) != salt.length)
|
||||
throw new IOException("Invalid file size");
|
||||
if (raw.read(prefix) != prefix.length)
|
||||
throw new IOException("Invalid file size");
|
||||
Helper.readBuffer(raw, salt);
|
||||
Helper.readBuffer(raw, prefix);
|
||||
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
|
||||
KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, KEY_ITERATIONS, KEY_LENGTH);
|
||||
|
|
|
@ -1124,6 +1124,16 @@ public class Helper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void readBuffer(InputStream is, byte[] buffer) throws IOException {
|
||||
int left = buffer.length;
|
||||
while (left > 0) {
|
||||
int count = is.read(buffer, buffer.length - left, left);
|
||||
if (count < 0)
|
||||
throw new IOException("EOF");
|
||||
left -= count;
|
||||
}
|
||||
}
|
||||
|
||||
static void copy(File src, File dst) throws IOException {
|
||||
try (InputStream in = new FileInputStream(src)) {
|
||||
try (FileOutputStream out = new FileOutputStream(dst)) {
|
||||
|
|
Loading…
Reference in New Issue