Created
July 9, 2012 20:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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