Skip to content

Instantly share code, notes, and snippets.

@babanin
Created April 6, 2014 17:33
Show Gist options
  • Save babanin/10009104 to your computer and use it in GitHub Desktop.
Save babanin/10009104 to your computer and use it in GitHub Desktop.
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