Created
April 6, 2014 17:33
-
-
Save babanin/10009104 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.security.MessageDigest | |
import scala.io.Source | |
/** | |
* Created by Ivan Babanin ([email protected]) on 4/6/2014 | |
*/ | |
object MD5File { | |
def hash(filePath: String): String = | |
MessageDigest.getInstance("MD5").digest(Source.fromFile(filePath).map(_.toByte).toArray) | |
.map( 0xFF & _ ) | |
.map { "%02x".format(_) } | |
.foldLeft("") { _ + _ } | |
def main(args: Array[String]) { | |
println(hash("src/MD5File.scala")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment