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

sangria.relay.util.Base64.scala Maven / Gradle / Ivy

The newest version!
package sangria.relay.util

import java.nio.charset.StandardCharsets

import scala.util.Try

object Base64 {
  private def toString(bytes: Array[Byte]) = new String(bytes, StandardCharsets.UTF_8)

  def encode(bytes: Array[Byte]): String = toString(java.util.Base64.getEncoder.encode(bytes))

  def encode(string: String): String = encode(string.getBytes(StandardCharsets.UTF_8))

  def decode(base64String: String): Option[String] =
    Try(java.util.Base64.getDecoder.decode(base64String)).map(toString).toOption
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy