Scala library with PKCS1EncodedKeySpec class which represents PKCS#1 encoded key.
- Scala 2.10+
- sbt 0.13+
If you want to use this library in your SBT project, just add these lines to your build.sbt
file:
libraryDependencies += "co.verdigris.security.specs" % "spec-pkcs1" % "0.1.0"
resolvers += "Verdigris Security Specs" at "https://verdigristech.github.io/spec-pkcs1/"
To generate an instance of PrivateKey,
instantiate PKCS1EncodedKeySpec
with a byte array representation of PKCS#1 encoding and pass it to generatePrivate
method of a KeyFactory instance.
val pemStr = scala.io.Source.fromFile("privateKey.pem")
val pemByteArray = Base64.decodeBase64(
pemStr.stripPrefix("-----BEGIN RSA PRIVATE KEY-----")
.stripSuffix("-----END RSA PRIVATE KEY-----"))
val kf = KeyFactory.getInstance("RSA")
val keySpec = new PKCS1EncodedKeySpec(pemByteArray)
val privateKey = kf.generatePrivate(keySpec)
To build this library from source manually, just run:
$ sbt package
The JAR file should be generated at ./target/scala-2.1X/security-specs-pkcs1_2.10-0.1.0.jar
.
Distributed under Apache 2.0 license. See LICENSE.md for more information.