signal-cli/src/main/java/org/asamk/signal/manager/KeyUtils.java
AsamK 5f2190713a Use custom SecureRandom instance
- Use NativePRNG algorithm instead of using SHA1PRNG if available
- Register a custom security provider to use the same SecureRandom everywhere
2018-11-25 22:07:34 +01:00

37 lines
826 B
Java

package org.asamk.signal.manager;
import org.asamk.signal.util.RandomUtils;
import org.whispersystems.signalservice.internal.util.Base64;
class KeyUtils {
private KeyUtils() {
}
static String createSignalingKey() {
return getSecret(52);
}
static byte[] createProfileKey() {
return getSecretBytes(32);
}
static String createPassword() {
return getSecret(18);
}
static byte[] createGroupId() {
return getSecretBytes(16);
}
private static String getSecret(int size) {
byte[] secret = getSecretBytes(size);
return Base64.encodeBytes(secret);
}
private static byte[] getSecretBytes(int size) {
byte[] secret = new byte[size];
RandomUtils.getSecureRandom().nextBytes(secret);
return secret;
}
}