Categorygithub.com/kmesiab/go-key-rotator
modulepackage
0.0.0-20240119054627-d4c0c7a68410
Repository: https://github.com/kmesiab/go-key-rotator.git
Documentation: pkg.go.dev

# README

Go Key Rotator 🔐

Golang License

Build Lint Test Go Report Card

Overview

go_key_rotator is a Go package designed for robust RSA key management. It facilitates generating, rotating, and encoding RSA private keys, and integrates seamlessly with AWS Parameter Store for secure key storage and retrieval. This package is particularly useful for applications that require cryptographic operations like token signing and data encryption.

Features

  • RSA key pair generation
  • PEM encoding for RSA keys
  • Secure storage and retrieval of keys via AWS Parameter Store
  • Automatic key rotation for enhanced security

Installation

To install go_key_rotator, use the go get command:

go get github.com/kmesiab/go_key_rotator

This will download the package along with its dependencies.

Usage

Here's a simple example of how to use go_key_rotator:

package main

import (
   "log"
   "github.com/kmesiab/go_key_rotator"
)

func main() {
   // Example: Using go_key_rotator for RSA key management

   // Create a rotator and give it a ParameterStoreInterface
   keyRotator := rotator.NewKeyRotator(
      rotator.NewAWSParameterStore(sess),
   )

   // Call Rotate and tell it where to store your keys
   // how big to make them
   privateKey, publicKey, err = keyRotator.Rotate(
      psPrivateKeyName, psPublicKeyName, 2048,
   )   
   
   if err != nil {
      log.Fatalf("Failed to rotate private key: %v", err)
   }
   
   log.Println("New RSA keys generated and stored.")
}

Get the current keys

   currentPrivateKey, err := go_key_rotator.GetCurrentRSAPrivateKey()
   if err != nil {
      log.Fatalf("Failed to retrieve current private key: %v", err)
   }

   currentPublicKey, err := go_key_rotator.GetCurrentRSAPublicKey()
   if err != nil {
      log.Fatalf("Failed to retrieve current public key: %v", err)
   }
}

# Packages

No description provided by the author

# Functions

EncodePrivateKeyToPEM converts an RSA private key into PEM (Privacy Enhanced Mail) format.
EncodePublicKeyToPEM to encode an RSA public key to PEM format.
NewAWSParameterStore creates and returns a new instance of AWSParameterStore.
NewKeyRotator creates a new instance of KeyRotator with the given ParameterStore.
NewMockParameterStore creates and returns a new instance of MockParameterStore.

# Constants

Exported constants.
Exported constants.
Exported constants.
Exported constants.
Exported constants.

# Structs

AWSParameterStore is an implementation of the ParameterStoreInterface that interfaces with the AWS Parameter Store.
No description provided by the author
MockParameterStore with error simulation capability.

# Interfaces

No description provided by the author