rsa

package
v1.9.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rsa implements RSA envelope encryption using JWE (JSON Web Encryption) format. It conforms to the interface in the envelope package.

The implementation uses:

  • RSA-OAEP-256 (RSA-OAEP with SHA-256) for key encryption
  • AES-256-GCM (A256GCM) for content encryption
  • JWE Compact Serialization format as defined in RFC 7516

The output is a JWE string with 5 base64url-encoded parts separated by dots: header.encryptedKey.iv.ciphertext.tag

Index

Constants

View Source
const (

	// EncryptionType is the type identifier for RSA JWE encryption
	EncryptionType = "JWE-RSA"
)

Variables

This section is empty.

Functions

func LoadPublicKeyFromPEM

func LoadPublicKeyFromPEM(pemBytes []byte) (*rsa.PublicKey, error)

LoadPublicKeyFromPEM parses an RSA public key from PEM-encoded bytes. The PEM block should be of type "PUBLIC KEY" or "RSA PUBLIC KEY".

func LoadPublicKeyFromPEMFile

func LoadPublicKeyFromPEMFile(path string) (*rsa.PublicKey, error)

LoadPublicKeyFromPEMFile reads and parses an RSA public key from a PEM file.

Types

type Encryptor

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

Encryptor provides envelope encryption using RSA-OAEP-256 for key wrapping and AES-256-GCM for data encryption, outputting JWE Compact Serialization format.

func NewEncryptor

func NewEncryptor(keyID string, publicKey *rsa.PublicKey) (*Encryptor, error)

NewEncryptor creates a new Encryptor with the provided RSA public key. The RSA key must be at least minRSAKeySize bits. The encryptor will use RSA-OAEP-256 for key encryption and A256GCM for content encryption.

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(data []byte) (*envelope.EncryptedData, error)

Encrypt performs envelope encryption on the provided data. It returns an EncryptedData struct containing JWE Compact Serialization format and type metadata. The JWE uses RSA-OAEP-256 for key encryption and A256GCM for content encryption.

Jump to

Keyboard shortcuts

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