]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/manager/KeyUtils.java
bd093e797d793f010c335b642c80ed45d936dce3
[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[] createGroupId() {
30 return getSecretBytes(16);
31 }
32
33 static byte[] createUnrestrictedUnidentifiedAccess() {
34 return getSecretBytes(16);
35 }
36
37 static byte[] createStickerUploadKey() {
38 return getSecretBytes(64);
39 }
40
41 private static String getSecret(int size) {
42 byte[] secret = getSecretBytes(size);
43 return Base64.encodeBytes(secret);
44 }
45
46 private static byte[] getSecretBytes(int size) {
47 byte[] secret = new byte[size];
48 RandomUtils.getSecureRandom().nextBytes(secret);
49 return secret;
50 }
51 }