1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +00:00

Crypto: Only create random generator as needed.

This commit is contained in:
Tom Hacohen 2017-03-29 12:02:13 +01:00
parent 93f757be3e
commit 225d01c143

View File

@ -47,10 +47,9 @@ public class Helpers {
}
static class Cipher {
SecureRandom random;
private SecureRandom _random = null;
Cipher() {
random = new SecureRandom();
}
private static final int blockSize = 16; // AES's block size in bytes
@ -94,7 +93,7 @@ public class Helpers {
byte[] encrypt(String keyBase64, byte[] data) {
byte[] iv = new byte[blockSize];
random.nextBytes(iv);
getRandom().nextBytes(iv);
BufferedBlockCipher cipher = getCipher(keyBase64, iv, true);
@ -111,6 +110,13 @@ public class Helpers {
return buf;
}
private SecureRandom getRandom() {
if (_random == null) {
_random = new SecureRandom();
}
return _random;
}
}
static String sha256(String base) {