mirror of
https://github.com/etesync/android
synced 2025-05-29 04:08:48 +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 {
|
static class Cipher {
|
||||||
SecureRandom random;
|
private SecureRandom _random = null;
|
||||||
|
|
||||||
Cipher() {
|
Cipher() {
|
||||||
random = new SecureRandom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int blockSize = 16; // AES's block size in bytes
|
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[] encrypt(String keyBase64, byte[] data) {
|
||||||
byte[] iv = new byte[blockSize];
|
byte[] iv = new byte[blockSize];
|
||||||
random.nextBytes(iv);
|
getRandom().nextBytes(iv);
|
||||||
|
|
||||||
BufferedBlockCipher cipher = getCipher(keyBase64, iv, true);
|
BufferedBlockCipher cipher = getCipher(keyBase64, iv, true);
|
||||||
|
|
||||||
@ -111,6 +110,13 @@ public class Helpers {
|
|||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SecureRandom getRandom() {
|
||||||
|
if (_random == null) {
|
||||||
|
_random = new SecureRandom();
|
||||||
|
}
|
||||||
|
return _random;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String sha256(String base) {
|
static String sha256(String base) {
|
||||||
|
Loading…
Reference in New Issue
Block a user