mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Crypto: Only create random generator as needed.
This commit is contained in:
parent
93f757be3e
commit
225d01c143
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user