Oh, and wg genpsk (not genkey) is just: SecureRandom random = new SecureRandom(); byte privateKey[] = new byte[32]; random.nextBytes(privateKey);