/**
   * This method calculates the secret key given a random byte buffer.
   *
   * @param secretKey a random byte buffer.
   * @return the secret key.
   */
  private String calculateSecretKey(byte[] secretKey) {
    Base32 codec = new Base32();
    byte[] encodedKey = codec.encode(secretKey);

    // Creating a string with the Base32 encoded bytes.
    return new String(encodedKey);
  }
Esempio n. 2
0
  public static String generateSecret() {

    // Allocating the buffer
    byte[] buffer = new byte[SECRET_SIZE];

    // Filling the buffer with random numbers.
    rand.nextBytes(buffer);

    // Getting the key and converting it to Base32
    Base32 codec = new Base32();
    byte[] secretKey = Arrays.copyOf(buffer, SECRET_SIZE);
    byte[] encodedKey = codec.encode(secretKey);
    return new String(encodedKey);
  }
 public static String encryptUserInfo(String userInfo) {
   byte[] bytes = Base32DecEnc.encode(userInfo.getBytes(UTF8));
   return ENCRYPTED_PREFIX.concat(new String(bytes, UTF8));
 }