signal-cli/src/main/java/cli/Util.java
2015-08-07 13:22:15 +02:00

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);
}
}
}