1 package org
.asamk
.signal
.manager
.util
;
3 import org
.asamk
.signal
.util
.RandomUtils
;
4 import org
.signal
.zkgroup
.InvalidInputException
;
5 import org
.signal
.zkgroup
.profiles
.ProfileKey
;
6 import org
.whispersystems
.libsignal
.IdentityKey
;
7 import org
.whispersystems
.libsignal
.IdentityKeyPair
;
8 import org
.whispersystems
.libsignal
.ecc
.Curve
;
9 import org
.whispersystems
.libsignal
.ecc
.ECKeyPair
;
10 import org
.whispersystems
.libsignal
.ecc
.ECPrivateKey
;
11 import org
.whispersystems
.signalservice
.api
.kbs
.MasterKey
;
12 import org
.whispersystems
.util
.Base64
;
14 public class KeyUtils
{
19 public static IdentityKeyPair
generateIdentityKeyPair() {
20 ECKeyPair djbKeyPair
= Curve
.generateKeyPair();
21 IdentityKey djbIdentityKey
= new IdentityKey(djbKeyPair
.getPublicKey());
22 ECPrivateKey djbPrivateKey
= djbKeyPair
.getPrivateKey();
24 return new IdentityKeyPair(djbIdentityKey
, djbPrivateKey
);
27 public static String
createSignalingKey() {
31 public static ProfileKey
createProfileKey() {
33 return new ProfileKey(getSecretBytes(32));
34 } catch (InvalidInputException e
) {
35 throw new AssertionError("Profile key is guaranteed to be 32 bytes here");
39 public static String
createPassword() {
43 public static byte[] createStickerUploadKey() {
44 return getSecretBytes(32);
47 public static MasterKey
createMasterKey() {
48 return MasterKey
.createNew(RandomUtils
.getSecureRandom());
51 private static String
getSecret(int size
) {
52 byte[] secret
= getSecretBytes(size
);
53 return Base64
.encodeBytes(secret
);
56 public static byte[] getSecretBytes(int size
) {
57 byte[] secret
= new byte[size
];
58 RandomUtils
.getSecureRandom().nextBytes(secret
);