crypto

package
v0.0.0-...-0f5ab51 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBase64URL

func DecodeBase64URL(s string) ([]byte, error)

DecodeBase64URL decodes a base64url string without padding.

func DecryptAESGCM

func DecryptAESGCM(ciphertext []byte, salt []byte, serverPubKeyBytes []byte, privateKey *ecdh.PrivateKey, authSecret []byte) ([]byte, error)

DecryptAESGCM decrypts a Web Push message encrypted with the older aesgcm scheme (draft-ietf-webpush-encryption). The salt and server public key come from the HTTP headers (Encryption and Crypto-Key), not from the payload itself.

func DecryptMessage

func DecryptMessage(payload []byte, privateKey *ecdh.PrivateKey, authSecret []byte) ([]byte, error)

DecryptMessage decrypts a Web Push message encrypted with RFC 8291 (aes128gcm).

func EncodeBase64URL

func EncodeBase64URL(data []byte) string

EncodeBase64URL encodes bytes to base64url without padding.

func GenerateAuthSecret

func GenerateAuthSecret() ([]byte, error)

GenerateAuthSecret generates a 16-byte random auth secret for Web Push.

func GenerateInstanceID

func GenerateInstanceID() ([]byte, error)

GenerateInstanceID generates an 8-byte instance ID with first nibble set to 0x7 (Chrome convention).

Types

type KeyPair

type KeyPair struct {
	PrivateKey *ecdh.PrivateKey
	PublicKey  *ecdh.PublicKey
}

KeyPair holds an ECDH P-256 key pair for Web Push.

func GenerateKeyPair

func GenerateKeyPair() (*KeyPair, error)

GenerateKeyPair generates a new ECDH P-256 key pair.

func PrivateKeyFromBytes

func PrivateKeyFromBytes(raw []byte) (*KeyPair, error)

PrivateKeyFromBytes reconstructs an ECDH P-256 private key from raw 32 bytes.

Jump to

Keyboard shortcuts

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