2010-10-26 09:29:04 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
exec scala "$0" "$@"
|
|
|
|
|
!#
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
|
|
|
|
*/
|
|
|
|
|
import java.security.{MessageDigest, SecureRandom}
|
|
|
|
|
|
|
|
|
|
lazy val random = SecureRandom.getInstance("SHA1PRNG")
|
|
|
|
|
|
2010-10-26 12:04:32 +02:00
|
|
|
val buffer = Array.fill(32)(0.byteValue)
|
2010-10-26 09:29:04 +02:00
|
|
|
random.nextBytes(buffer)
|
|
|
|
|
|
2010-10-26 12:04:32 +02:00
|
|
|
val digest = MessageDigest.getInstance("SHA1")
|
2010-10-26 09:29:04 +02:00
|
|
|
digest.update(buffer)
|
|
|
|
|
val bytes = digest.digest
|
|
|
|
|
|
|
|
|
|
val sb = new StringBuilder
|
|
|
|
|
val hex = "0123456789ABCDEF"
|
|
|
|
|
bytes.foreach { b =>
|
|
|
|
|
val n = b.asInstanceOf[Int]
|
|
|
|
|
sb.append(hex.charAt((n & 0xF) >> 4)).append(hex.charAt(n & 0xF))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println("Cryptographically secure cookie:")
|
|
|
|
|
println(sb.toString)
|