An implementation to securely hold a private string in memory implemented in Scala 2.10.3.
valpassword=Array[Char]('p', 'a', 's', 's')
valsecurestring=SecureString(password)
// original array is wiped out
println(password.toSeq) // prints 4 times the char '\0'// access the secret string// encrypted string is decrypted and passed to the inner funciton
securestring.read { plain =>
println(plain.mkString) // prints "pass"
}
// after the inner function the decrypted char array is automatically wiped outAdd the following configuration to your build.sbt:
resolvers +="repo.choffmeister.de" at "http://repo.choffmeister.de/maven2"
libraryDependencies +="de.choffmeister"%%"securestring"%"0.0.1"