Skip to content

ikerlan-digital/spec-pkcs1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spec-pkcs1 Build Status License

Scala library with PKCS1EncodedKeySpec class which represents PKCS#1 encoded key.

Prerequisites

  • Scala 2.10+
  • sbt 0.13+

Specifying Dependency

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/"

Usage

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)

Building

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.

License

Distributed under Apache 2.0 license. See LICENSE.md for more information.