encryption

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesGcmDecrypt

func AesGcmDecrypt(encryptedData []byte, specs CipherKeySpecs) ([]byte, error)

AesGcmDecrypt decrypts the given data using AES-GCM.

func AesGcmEncrypt

func AesGcmEncrypt(plainData []byte, specs CipherKeySpecs) ([]byte, error)

AesGcmEncrypt encrypts the plainData using the AES-GCM AEAD cipher

func ChaChaDecrypt

func ChaChaDecrypt(encryptedData []byte, specs CipherKeySpecs) ([]byte, error)

ChaChaDecrypt decrypts the encryptedData using the ChaCha20-Poly1305 AEAD cipher

func ChaChaEncrypt

func ChaChaEncrypt(plainData []byte, specs CipherKeySpecs) ([]byte, error)

ChaChaEncrypt encrypts the plainData using the ChaCha20-Poly1305 AEAD cipher

func ComputeAESSharedSecret

func ComputeAESSharedSecret(specs CipherKeySpecs) (sharedSecret []byte, err error)

ComputeAESSharedSecret computes the shared secret using elliptic curve Diffie-Hellman

func ComputeChaChaSharedSecret

func ComputeChaChaSharedSecret(specs CipherKeySpecs) (sharedSecret []byte, err error)

ComputeChaChaSharedSecret computes the shared secret using elliptic curve Diffie-Hellman

func ComputeX25519SharedKey added in v0.1.4

func ComputeX25519SharedKey(SharedPublicKey, PrivateKey string) (sharedSecret []byte, err error)

ComputeX25519SharedKey computes the shared secret using elliptic curve Diffie-Hellman SharedPublicKey and PrivateKey must be hex encoded as strings Returns the shared secret as a byte slice

func GenerateSalt added in v0.1.4

func GenerateSalt() (string, error)

GenerateSalt generates a random salt Returns the salt as a hex encoded string

func ParsePBKDF2Iterations added in v0.1.4

func ParsePBKDF2Iterations(iterations string) int

ParsePBKDF2Iterations parses the PBKDF2 iterations Returns the iterations as an int

func SafeStringToInt added in v0.1.4

func SafeStringToInt(s string) (int, error)

SafeStringToInt converts a string to an int Returns an error if the string cannot be converted to an int

Types

type AlgoMethod

type AlgoMethod string
const (
	XChaCha20_Poly1305_PBKDF2_Curve25519 AlgoMethod = "XChaCha20_Poly1305_PBKDF2_Curve25519"
	AES256_GCM_PBKDF2_Curve25519         AlgoMethod = "AES256_GCM_PBKDF2_Curve25519"
)

type CipherKeySpecs

type CipherKeySpecs struct {
	Salt            string     `json:"salt"`
	Iterations      string     `json:"iterations"`
	SharedPublicKey string     `json:"sharedPublicKey"`
	PrivateKey      string     `json:"privateKey"`
	Algo            AlgoMethod `json:"algo"`
}

type X25519KeyPair

type X25519KeyPair struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
}

func GenerateKeyPair

func GenerateKeyPair() (keyPair X25519KeyPair, err error)

GenerateKeyPair generates a new X25519 key pair.

Jump to

Keyboard shortcuts

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