snippets/zd/gen_user_id.scala
2024-11-02 20:34:57 +08:00

14 lines
No EOL
330 B
Scala

//> using dep com.google.guava:guava:33.3.0-jre
import com.google.common.base.Charsets
import com.google.common.hash.Hashing
@main
def genId(id: String, key: String) = {
val sign = sha256(id + sha256(key))
println(s"${id}|${sign}")
}
def sha256(str: String) = {
Hashing.sha256().hashString(str, Charsets.UTF_8).toString
}