Help us shape the future of Go! Take the 2026 Go Developer Survey

rsa

package
v1.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

pki/rsa

Import path: github.com/InsideGallery/core/pki/rsa

pki/rsa is the legacy RSA-OAEP cipher package. New code should prefer github.com/InsideGallery/core/pki/rsaoaep, which exposes the same behavior without colliding with Go's standard crypto/rsa package name.

Main API

  • RSA implements the pki.Cipher interface.
  • NewRSA(bits) generates a new RSA private key and matching public key.
  • DefaultBitsSize is the default key size, currently 4096 bits.
  • FromPrivateKey(data) restores a cipher from PKCS#1 private-key PEM data.
  • TypeRSAPrivateKey is the PEM block type used by ToBinary.
  • ErrFailedToParsePEMBlock reports data that is not a private-key PEM block.
  • Kind() returns "rsa".
  • Encrypt(data) uses RSA-OAEP with SHA-256 and a nil label.
  • Decrypt(data) decrypts the RSA-OAEP ciphertext with the private key.
  • ToBinary() returns PKCS#1 private-key PEM bytes.
  • FromBinary(raw) restores a cipher through FromPrivateKey.

Usage

package example

import corersa "github.com/InsideGallery/core/pki/rsa"

func roundTrip(plaintext []byte) ([]byte, error) {
	cipher, err := corersa.NewRSA(corersa.DefaultBitsSize)
	if err != nil {
		return nil, err
	}

	ciphertext, err := cipher.Encrypt(plaintext)
	if err != nil {
		return nil, err
	}

	return cipher.Decrypt(ciphertext)
}

Security and Compatibility Notes

RSA-OAEP can encrypt only short messages relative to the key size and hash overhead. Use it for small payloads such as wrapped keys, not large data streams. ToBinary exposes private-key material; store it only in a suitable secret store. This legacy path remains available for existing consumers; prefer pki/rsaoaep for new code.

Documentation

Overview

Package rsa is the legacy RSA-OAEP import path.

New code should import the focused replacement package:

import "github.com/InsideGallery/core/pki/rsaoaep"

Compatibility: existing RSA-OAEP exports remain available for downstream consumers that still import pki/rsa. Do not add new helpers here; add RSA-OAEP behavior to pki/rsaoaep so call sites avoid a local name collision with crypto/rsa.

Index

Constants

View Source
const (
	TypeRSAPrivateKey = "RSA PRIVATE KEY"

	DefaultBitsSize = 4096
)

Variables

View Source
var (
	ErrFailedToParsePEMBlock = errors.New("failed to parse PEM block containing the public key")
)

All kind of errors

Functions

This section is empty.

Types

type RSA

type RSA struct {
	// contains filtered or unexported fields
}

func FromPrivateKey

func FromPrivateKey(b []byte) (*RSA, error)

func NewRSA

func NewRSA(bits int) (*RSA, error)

func (*RSA) Decrypt

func (a *RSA) Decrypt(data []byte) ([]byte, error)

func (*RSA) Encrypt

func (a *RSA) Encrypt(data []byte) ([]byte, error)

func (*RSA) FromBinary

func (a *RSA) FromBinary(raw []byte) (localCipher.Cipher, error)

func (*RSA) Kind

func (a *RSA) Kind() string

func (*RSA) ToBinary

func (a *RSA) ToBinary() ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL