1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00
kube-arangodb/deps/github.com/pavel-v-chernykh/keystore-go
2018-03-09 17:02:58 +01:00
..
examples Implementing TLS support 2018-03-09 17:02:58 +01:00
.gitignore Implementing TLS support 2018-03-09 17:02:58 +01:00
common.go Implementing TLS support 2018-03-09 17:02:58 +01:00
common_test.go Implementing TLS support 2018-03-09 17:02:58 +01:00
decoder.go Implementing TLS support 2018-03-09 17:02:58 +01:00
decoder_test.go Implementing TLS support 2018-03-09 17:02:58 +01:00
encoder.go Implementing TLS support 2018-03-09 17:02:58 +01:00
keyprotector.go Implementing TLS support 2018-03-09 17:02:58 +01:00
keystore.go Implementing TLS support 2018-03-09 17:02:58 +01:00
LICENSE Implementing TLS support 2018-03-09 17:02:58 +01:00
README.md Implementing TLS support 2018-03-09 17:02:58 +01:00

Keystore

A go (golang) implementation of Java KeyStore encoder/decoder

Take into account that JKS assumes that private keys are PKCS8 encoded.

Example

package main

import (
	"github.com/pavel-v-chernykh/keystore-go"
	"log"
	"os"
	"reflect"
)

func readKeyStore(filename string, password []byte) keystore.KeyStore {
	f, err := os.Open(filename)
	defer f.Close()
	if err != nil {
		log.Fatal(err)
	}
	keyStore, err := keystore.Decode(f, password)
	if err != nil {
		log.Fatal(err)
	}
	return keyStore
}

func writeKeyStore(keyStore keystore.KeyStore, filename string, password []byte) {
	o, err := os.Create(filename)
	defer o.Close()
	if err != nil {
		log.Fatal(err)
	}
	err = keystore.Encode(o, keyStore, password)
	if err != nil {
		log.Fatal(err)
	}
}

func zeroing(s []byte) {
	for i := 0; i < len(s); i++ {
		s[i] = 0
	}
}

func main() {
	password := []byte{'p', 'a', 's', 's', 'w', 'o', 'r', 'd'}
	defer zeroing(password)
	ks1 := readKeyStore("keystore.jks", password)

	writeKeyStore(ks1, "keystore2.jks", password)

	ks2 := readKeyStore("keystore2.jks", password)

	log.Printf("Is equal: %v\n", reflect.DeepEqual(ks1, ks2))
}

For more examples explore examples dir