I'm building a server side application in scala which needs to create a JWT to communicate with a third party API.
Due to dependency reasons, I am using the Java JWT Library as opposed to a Scala equivalent.
The current infrastructure injects a string for the public and private keys among other bits of sensitive server configuration at run-time, so I need to be able to use keys as strings in the format
-----BEGIN PUBLIC KEY-----
<Base64 Bob>
-----END PUBLIC KEY-----
so far, I have
private def newJWT(..., private: String, public: String) = Try {
val privateKey: RSAPrivateKey = ???
val publicKey: RSAPublicKey = ???
val algorithm: Algorithm = Algorithm.RSA256(publicKey, privateKey)
val token: String = JWT.create().
// ...
.sign(algorithm)
// ...
token
}
How can I convert my string encoded keys into the required RSAPrivateKey interfaced types in the simplest way?