Last active
March 9, 2022 10:39
-
-
Save ElectricCoffee/01281d745e33823aff72 to your computer and use it in GitHub Desktop.
A very simple checksum generator written in scala, the following checksum types have been tested: MD2 MD5 SHA SHA-256 SHA-512
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
package your.pkg.here | |
import java.security.MessageDigest | |
import java.nio.file.{Files, Paths} | |
object Generator { | |
implicit class Helper(val sc: StringContext) extends AnyVal { | |
def md5(): String = generate("MD5", sc.parts(0)) | |
def sha(): String = generate("SHA", sc.parts(0)) | |
def sha256(): String = generate("SHA-256", sc.parts(0)) | |
} | |
// t is the type of checksum, i.e. MD5, or SHA-512 or whatever | |
// path is the path to the file you want to get the hash of | |
def generate(t: String, path: String): String = { | |
val arr = Files readAllBytes (Paths get path) | |
val checksum = MessageDigest.getInstance(t) digest arr | |
checksum.map("%02X" format _).mkString | |
} | |
} |
Thank you
thank you
Thank you for sharing it !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!