package org.asamk.signal.manager;
-import org.whispersystems.signalservice.internal.util.Base64;
+import org.asamk.signal.util.RandomUtils;
+import org.signal.zkgroup.InvalidInputException;
+import org.signal.zkgroup.profiles.ProfileKey;
+import org.whispersystems.util.Base64;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-
-class KeyUtils {
+public class KeyUtils {
private KeyUtils() {
}
return getSecret(52);
}
- static byte[] createProfileKey() {
- return getSecretBytes(32);
+ static ProfileKey createProfileKey() {
+ try {
+ return new ProfileKey(getSecretBytes(32));
+ } catch (InvalidInputException e) {
+ throw new AssertionError("Profile key is guaranteed to be 32 bytes here");
+ }
}
static String createPassword() {
return getSecret(18);
}
- static byte[] createGroupId() {
- return getSecretBytes(16);
+ static byte[] createStickerUploadKey() {
+ return getSecretBytes(32);
}
private static String getSecret(int size) {
return Base64.encodeBytes(secret);
}
- private static byte[] getSecretBytes(int size) {
+ public static byte[] getSecretBytes(int size) {
byte[] secret = new byte[size];
- getSecureRandom().nextBytes(secret);
+ RandomUtils.getSecureRandom().nextBytes(secret);
return secret;
}
-
- private static SecureRandom getSecureRandom() {
- try {
- return SecureRandom.getInstance("SHA1PRNG");
- } catch (NoSuchAlgorithmException e) {
- throw new AssertionError(e);
- }
- }
}