cryptoutils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AES_KEY_SIZE            = 32
	AES_MIN_CIPHERTEXT_SIZE = aes.BlockSize + 12
)
View Source
const (
	RSA_KEY_SIZE   = 4096
	SIGNATURE_SIZE = 512
	SALT_SIZE      = 16
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(ciphertext []byte, key []byte) ([]byte, error)

decrypts a ciphertext encrypted with AesEncrypt

func AesEncrypt

func AesEncrypt(plaintext []byte, key []byte) ([]byte, error)

encrypts a provided plaintext with AES256 in GCM mode, and appends a nonce to the start of the ciphertext

func ExportRsaPrivateKey added in v0.1.2

func ExportRsaPrivateKey(prvKey *rsa.PrivateKey, keyPath string, password []byte) error

func ExportRsaPub

func ExportRsaPub(pubKey *rsa.PublicKey) []byte

exports the pem-encoded byte array of a given RSA key

func GenAesKey

func GenAesKey() []byte

returns a radnomly generated 256-bit aes key

func GenNonce

func GenNonce() []byte

generates a randomized nonce to be used for key challenges

func GenerateRsaKeys

func GenerateRsaKeys(keyPath string, password []byte) error

generates a pair of RSA keys and saves them to the provided path

func HashKey added in v0.1.1

func HashKey(password []byte, salt []byte, rounds int) []byte

generates an AES key from a password, by hashing it with a salt repeatedly

func ImportRsa

func ImportRsa(keyPath string, password []byte) (rsa.PrivateKey, rsa.PublicKey, error)

imports a pair of RSA keys from a file path

func ImportRsaPrivateKey added in v0.1.2

func ImportRsaPrivateKey(keyPath string, password []byte) (*rsa.PrivateKey, error)

func ImportRsaPub

func ImportRsaPub(pemStr []byte) (rsa.PublicKey, error)

imports an RSA public key from a byte string of the pem-encoded key

func RsaDecrypt

func RsaDecrypt(prvKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)

decrypts a given plaintext with the provided private key

func RsaEncrypt

func RsaEncrypt(pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error)

encrypts a given plaintext with the provided public key

func RsaSign

func RsaSign(prvKey rsa.PrivateKey, plaintext []byte) ([]byte, error)

func RsaVerify

func RsaVerify(pubKey rsa.PublicKey, plaintext []byte, signature []byte) bool

func StripZeroes added in v0.1.2

func StripZeroes(slice []byte) []byte

a helper function to strip zeroes from the beginning of a byte slice this isn't necessarily related to AES inherently, however there isn't really a better place to put this function

Types

This section is empty.

Jump to

Keyboard shortcuts

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