Skip to content

Instantly share code, notes, and snippets.

@Vic020
Created December 23, 2016 07:18
Show Gist options
  • Save Vic020/001a89d4fe40e26f82a584cbef9ab7fc to your computer and use it in GitHub Desktop.
Save Vic020/001a89d4fe40e26f82a584cbef9ab7fc to your computer and use it in GitHub Desktop.
scala encryption util wrapper . Include md5 sha1 sha224 sha256 sha512
import java.security.MessageDigest
object EncryptionUtil {
def md5(string: String): String = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8")).map("%02x".format(_)).mkString
def sha1(string: String): String = MessageDigest.getInstance("SHA-1").digest(string.getBytes("UTF-8")).map("%02x".format(_)).mkString
def sha224(string: String): String = MessageDigest.getInstance("SHA-224").digest(string.getBytes("UTF-8")).map("%02x".format(_)).mkString
def sha256(string: String): String = MessageDigest.getInstance("SHA-256").digest(string.getBytes("UTF-8")).map("%02x".format(_)).mkString
def sha512(string: String): String = MessageDigest.getInstance("SHA-512").digest(string.getBytes("UTF-8")).map("%02x".format(_)).mkString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment