def MD5(input: String): String = { var md5: MessageDigest = null try { md5 = MessageDigest.getInstance("MD5") } catch { case e: Exception => { e.printStackTrace println(e.getMessage) } } val byteArray: Array[Byte] = input.getBytes val md5Bytes: Array[Byte] = md5.digest(byteArray) var hexValue: String = "" var i: Integer = 0 for ( i <- 0 to md5Bytes.length-1) { val str: Int = (md5Bytes(i).toInt) & 0xff println("str"+str) if (str < 16) { hexValue=hexValue+"0" } hexValue=hexValue+(Integer.toHexString(str)) } return hexValue.toString } def main(args: Array[String]) { //println(MD5("nihao1")) }
Scala MD5加密Util类
最新推荐文章于 2024-08-10 16:14:51 发布