This ScalaJS cross compiled RSA / Crypto library.
- RSA Key generation / import / export
- RSA Signing and Verifying
Add this to your build.sbt
"pl.setblack" %%% "cryptotpyrc" % "0.4"
val rsa = new UniCrypto.rsa
val generatedKeyPair = rsa.generateKeys()
...
generatedKeyPair.flatMap(
keyPairGeneration => {
val publicKeyJwk:Future[String] = keyPairGeneration.get.pub.export
val privKeyPKCS8:Future[String] = keyPairGeneration.get.priv.export
...
}
)
...
val signature:Future[String] = rsa.sign(privKey, "mymessage" )
..
val verified:Future[Boolean] = rsa.verify(publKey, singature, "mymessage")
- Uses Strings in API - makes it easy - not fast
- Uses JVM (java.security) and browser (SubtleCrypto) native libraries (may not work on NodeJS)
- Uses Future(s) in API (because of JavaScript) - crazy
- Same keys and signatures will work on both JVM and V8 ( You can sign on JVM and verify in browser or vice versa).
- It supports only RSA as for now
sbt test
runs only JVM part of tests- Rhine/ Node just does not work (SubtleCrypto...)
- To test in browser run
sbt appJS/test:fastOptJS
and then open provided test.html. (There are still issues with scalatest async tests, though.)