All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.jhipster.lite.generator.base64.domain.Base64Utils Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package tech.jhipster.lite.generator.base64.domain;

import java.security.SecureRandom;
import java.util.Base64;

public final class Base64Utils {

  private static final SecureRandom RANDOM = new SecureRandom();

  private Base64Utils() {}

  public static String getBase64Secret() {
    return Base64.getEncoder().encodeToString(getRandomHexString(64).getBytes());
  }

  private static String getRandomHexString(int length) {
    StringBuilder result = new StringBuilder();

    while (result.length() < length) {
      result.append(Integer.toHexString(RANDOM.nextInt()));
    }

    return result.substring(0, length);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy