Skip to content

Commit

Permalink
add base64 helpers methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-gray committed May 18, 2016
1 parent fd7426b commit 268ad2f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/scala/uk/gov/hmrc/crypto/crypto.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package uk.gov.hmrc.crypto

import org.apache.commons.codec.binary.Base64

trait Encrypter {
def encrypt(plain: PlainContent): Crypted
}
Expand All @@ -40,6 +42,14 @@ case class PlainText(value: String) extends PlainContent

case class PlainBytes(value: Array[Byte]) extends PlainContent

case class Crypted(value: String) extends AnyVal
case class Crypted(value: String) {
def toBase64 = Base64.encodeBase64(value.getBytes("UTF-8"))
}

case class Scrambled(value: String) extends AnyVal
object Crypted extends (String => Crypted) {
def fromBase64(s: String) = Crypted(new String(Base64.decodeBase64(s.getBytes("UTF-8"))))
}

case class Scrambled(value: String) {
def toBase64 = Base64.encodeBase64(value.getBytes("UTF-8"))
}

0 comments on commit 268ad2f

Please sign in to comment.