rsa v1

A Go package that provides a simple and secure interface for RSA key generation, management, and PEM encoding/decoding.

Repository

Installation

Features

  • Generate RSA key pairs with customizable bit sizes (minimum 1024 bits)

  • Convenient 4096-bit key generation for long-term security

  • PEM encoding/decoding for both public and private keys

  • Type-safe key handling with separate PublicKey and PrivateKey types

Usage

Generating New Keys

Working with Keys

Loading Keys from PEM

Error Handling

The package provides several error types for specific validation scenarios:

  • ErrInvalidBitSize: Returned when the requested key size is not positive or not a multiple of 8

  • ErrBitSizeTooSmall: Returned when the requested key size is less than 1024 bits

  • ErrInvalidPEM: Returned when parsing an invalid PEM-encoded public key

  • ErrNotRSAPublicKey: Returned when the parsed key is not an RSA public key

  • ErrInvalidPrivateKeyPEM: Returned when parsing an invalid PEM-encoded private key

  • ErrInvalidPrivateKey: Returned when the parsed private key is invalid

Security Recommendations

  • Use 4096-bit keys (New4096RSAKey()) for long-term security beyond 2030

  • Never share private keys or store them in plaintext

  • Always use secure random number generation (handled automatically by this package)

  • Keep your Go version updated to ensure you have the latest security patches

Last updated