rsa

package
v1.9.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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"
)
View Source
const (
	// HardcodedPublicKeyPEM contains a temporary hardcoded RSA public key (2048-bit) for envelope encryption.
	// This is a TEMPORARY solution for initial development and testing.
	// TODO: Replace with dynamic key fetching from CyberArk Discovery & Context API.
	HardcodedPublicKeyPEM = `` /* 450-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func LoadHardcodedPublicKey

func LoadHardcodedPublicKey() (*rsa.PublicKey, string, error)

LoadHardcodedPublicKey loads and parses the hardcoded RSA public key. Returns a hardcoded UID associated with the key. This is a temporary solution for initial development and testing. Returns an error if the hardcoded key is invalid or cannot be parsed.

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(fetcher keyfetch.KeyFetcher) (*Encryptor, error)

NewEncryptor creates a new Encryptor with the provided key fetcher. The encryptor will use RSA-OAEP-256 for key encryption and A256GCM for content encryption.

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(ctx context.Context, 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