mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
25 lines
650 B
Java
25 lines
650 B
Java
package cli;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.SecureRandom;
|
|
|
|
class Util {
|
|
public static String getSecret(int size) {
|
|
byte[] secret = getSecretBytes(size);
|
|
return Base64.encodeBytes(secret);
|
|
}
|
|
|
|
private static byte[] getSecretBytes(int size) {
|
|
byte[] secret = new byte[size];
|
|
getSecureRandom().nextBytes(secret);
|
|
return secret;
|
|
}
|
|
|
|
private static SecureRandom getSecureRandom() {
|
|
try {
|
|
return SecureRandom.getInstance("SHA1PRNG");
|
|
} catch (NoSuchAlgorithmException e) {
|
|
throw new AssertionError(e);
|
|
}
|
|
}
|
|
}
|