GithubHelp home page GithubHelp logo

mideo / keystore-manager Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 58 KB

License: Apache License 2.0

Scala 100.00%
scala jks https-certificate x509certificates java-keystore private-key secret-key

keystore-manager's Introduction

keystore Manager

Build Status

Maven Central

Key management module backed by Java KeyStore on file system as default storage
Usage
    //save certficatificate with default FileSystemJKeyStoreManager
    val certificates: Array[Certificate] = 	httpsURLConnection.getServerCertificates()
    val certManager: KeyStoreEntryManager = KeyStoreEntryManager.CertificateManager(KeyStoreManager.FileSystemJKeyStoreManager)
    
    certificates.foreach(
      certManager.saveCertificate(_, testKeyStoreName, password)
    )
    
    //Check certificate is known
    certificates.foreach(
      certManager.isKnown(_, testKeyStoreName, password)
    )
    
    //or implement custom KeyStoreManager
    object MongoJKeyStoreManagerImpl extends KeyStoreManager {
      override def create(keystoreAbsolutePath: String, password: String): KeyStore = {
        ....
      } 
    
      override def load(keyStoreAbsolutePath: String, password: String): KeyStore = {     
        ....
      } 
    
      override def isKnownCertificate(certificate: Certificate, keystoreName: String = "keystore.jks", password: String = "password"): Boolean = {
         ...                                                                                                                                               
      } 
    
      override def delete(path: String): Unit = {
         ...                                                                                                                                               
      } 
    
      override def save(keyStore: KeyStore, keystoreName: String, password: String): Unit = {
         ...                                                                                                                                                
       }
     
    }
    
    val mongoCertManager: KeyStoreEntryManager = KeyStoreEntryManager.CertificateManager(MongoJKeyStoreManagerImpl)
    
    
    //save private key entry
      protected def makePrivateKeyEntry():PrivateKeyEntry = {
        val gen = new CertAndKeyGen("RSA", "SHA1WithRSA")
        gen.generate(1024)
        val pk: PrivateKey = gen.getPrivateKey
        val cert: Certificate = certificateFactory.generateCertificate(getResourceFile("selfsigned.cert"))
        new PrivateKeyEntry(pk, Array(cert))
      }
    
      val testPrivateKeyEntry: PrivateKeyEntry = makePrivateKeyEntry()
      val privateKeyManager: KeyStoreEntryManager[PrivateKeyEntry] = KeyStoreEntryManager
        .PrivateKeyEntryManager(KeyStoreManager.FileSystemJKeyStoreManager, testKeyStoreName, password)

      privateKeyManager.save(testPrivateKeyEntry)
   
   // check is known private key
      privateKeyManager.isKnown(testPrivateKeyEntry) should be(true)
    //delete private key entry
    privateKeyManager.delete(testPrivateKeyEntry)
    
    
    
    
    //save a secret key entry
      val testSecretKeyEntry = new KeyStore.SecretKeyEntry(
        new SecretKeySpec(password.getBytes(), 0, password.getBytes().length, "AES"))
      val secretKeyManager: KeyStoreEntryManager[SecretKeyEntry] = KeyStoreEntryManager
        .SecretKeyEntryManager(KeyStoreManager.FileSystemJKeyStoreManager, testKeyStoreName, password)       
     secretKeyManager.save(testSecretKeyEntry)
    
    //check is known secret key entry
    secretKeyManager.isKnown(testSecretKeyEntry) 
     
    //delete secret key entry
    secretKeyManager.delete(testSecretKeyEntry)
    
    

keystore-manager's People

Contributors

mideo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.