Skip to content

Instantly share code, notes, and snippets.

@micke
Created October 22, 2014 09:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save micke/0c32417c550c9f3b6f63 to your computer and use it in GitHub Desktop.
Save micke/0c32417c550c9f3b6f63 to your computer and use it in GitHub Desktop.
Super simple scala wrapper around org.apache.commons.codec.binary.Base64
package utils
import org.apache.commons.codec.binary.{ Base64 => ApacheBase64 }
object Base64 {
def decode(encoded: String) = new String(ApacheBase64.decodeBase64(encoded.getBytes))
def encode(decoded: String) = new String(ApacheBase64.encodeBase64(decoded.getBytes))
}
import play.api.test._
import utils.Base64
class Base64 extends PlaySpecification {
"Base64.decode" should {
"decode the base64 encoded string and return a string" in {
val decoded = "hello world"
val encoded = "aGVsbG8gd29ybGQ="
Base64.decode(encoded) must equalTo(decoded)
}
}
"Base64.encode" should {
"encode the string and return a base64 encoded string" in {
val encoded = "aGVsbG8gd29ybGQ="
val decoded = "hello world"
Base64.encode(decoded) must equalTo(encoded)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment