Skip to content

Instantly share code, notes, and snippets.

@society20
Created July 9, 2012 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save society20/3078773 to your computer and use it in GitHub Desktop.
Save society20/3078773 to your computer and use it in GitHub Desktop.
Using Apache Commons Codec for decoding/encoding Base64 and encrypting with MD5/SHA-1
object ApplicationBuild extends Build {
val appName = "society20-app"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"commons-codec" % "commons-codec" % "1.6")
val main = PlayProject( appName, appVersion, appDependencies, mainLang = SCALA ).settings()
}
//Base64 encoding/decoding functions facilities
def EncodeBase64( email: String ): String =
org.apache.commons.codec.binary.Base64.encodeBase64String( email.getBytes )
def DecodeBase64( encodedUusername: String ): String =
new String( org.apache.commons.codec.binary.Base64.decodeBase64( encodedUusername ) )
import org.apache.commons.codec.digest.DigestUtils._
//Calculates the SHA-256 digest and returns the value as a hex string.
val dataInSha1 = sha256Hex( dataToCrypt )
val dataInMd5 = md5( dataToCrypt )
//see http://commons.apache.org/codec/api-release/org/apache/commons/codec/digest/DigestUtils.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment