]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/manager/KeyUtils.java
Refactor to use GroupId class to wrap the byte array
[signal-cli] / src / main / java / org / asamk / signal / manager / KeyUtils.java
1 package org.asamk.signal.manager;
2
3 import org.asamk.signal.util.RandomUtils;
4 import org.signal.zkgroup.InvalidInputException;
5 import org.signal.zkgroup.profiles.ProfileKey;
6 import org.whispersystems.util.Base64;
7
8 class KeyUtils {
9
10 private KeyUtils() {
11 }
12
13 static String createSignalingKey() {
14 return getSecret(52);
15 }
16
17 static ProfileKey createProfileKey() {
18 try {
19 return new ProfileKey(getSecretBytes(32));
20 } catch (InvalidInputException e) {
21 throw new AssertionError("Profile key is guaranteed to be 32 bytes here");
22 }
23 }
24
25 static String createPassword() {
26 return getSecret(18);
27 }
28
29 static byte[] createStickerUploadKey() {
30 return getSecretBytes(32);
31 }
32
33 private static String getSecret(int size) {
34 byte[] secret = getSecretBytes(size);
35 return Base64.encodeBytes(secret);
36 }
37
38 static byte[] getSecretBytes(int size) {
39 byte[] secret = new byte[size];
40 RandomUtils.getSecureRandom().nextBytes(secret);
41 return secret;
42 }
43 }