crypto

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: GPL-3.0 Imports: 22 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateRSAKeyPair

func CreateRSAKeyPair(password []byte) (string, string, error)

creates a private key, public key pem encoded pair

func CreateVPNKeyPair

func CreateVPNKeyPair(vpnType string) (string, string, error)

creates a key pair for the given vpn type

func KeyFromPassphrase

func KeyFromPassphrase(passphrase string, seed int64) []byte

in: passphrase - pass phrase to use to create the key in: seed - a seed value used to scramble the returned key hash out: a 32 byte key hash of the passphrase

func RandomKey

func RandomKey(len int) ([]byte, error)

in: len - the length of the key to generate out: a byte array of random bytes to use as the key

func ReseedKey

func ReseedKey(key []byte, origSeed, newSeed int64) []byte

in: key: the key to reseed in: origSeed: the original seed used to seed the hash of the passphrase in: newSeed: the new seed to apply out: the 32 byte key hash with new seed applied

Types

type Crypt

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

func NewCrypt

func NewCrypt(key []byte) (*Crypt, error)

func (*Crypt) Decrypt

func (c *Crypt) Decrypt(cipherData []byte) ([]byte, error)

func (*Crypt) DecryptB64

func (c *Crypt) DecryptB64(cipherDataB64 string) (string, error)

func (*Crypt) DecryptB64Raw

func (c *Crypt) DecryptB64Raw(cipherDataB64 string) ([]byte, error)

func (*Crypt) Encrypt

func (c *Crypt) Encrypt(plainData []byte) ([]byte, error)

func (*Crypt) EncryptB64

func (c *Crypt) EncryptB64(plainData string) (string, error)

func (*Crypt) EncryptB64Raw

func (c *Crypt) EncryptB64Raw(plainData []byte) (string, error)

type ECDHKey

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

func NewECDHKey

func NewECDHKey() (*ECDHKey, error)

creates a new ECDH key

func (*ECDHKey) PublicKey

func (key *ECDHKey) PublicKey() (string, error)

retrieves base64 encoded public key

func (*ECDHKey) PublicKeyForNodeJS

func (key *ECDHKey) PublicKeyForNodeJS() string

retrieves base64 encoded public key that can be used by nodejs crypto library

func (*ECDHKey) SharedSecret

func (key *ECDHKey) SharedSecret(otherPublicKey string) ([]byte, error)

retrieves a shared secret with another ECDH key using that key's public key

func (*ECDHKey) SharedSecretFromNodeJS

func (key *ECDHKey) SharedSecretFromNodeJS(otherPublicKey string) ([]byte, error)

retrieves a shared secret with a public key of an ecdh key created by nodejs

type RSAKey

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

func NewRSAKey

func NewRSAKey() (*RSAKey, error)

create a new RSA key

func NewRSAKeyFromFile

func NewRSAKeyFromFile(pemFilePath string, password []byte) (*RSAKey, error)

func NewRSAKeyFromPEM

func NewRSAKeyFromPEM(privateKeyPEM string, password []byte) (*RSAKey, error)

creates a new RSA key from PEM encoded data

func (*RSAKey) Decrypt

func (k *RSAKey) Decrypt(ciphertext []byte) ([]byte, error)

decrypts cipher text encrypted with the public key with the private key

func (*RSAKey) DecryptBase64

func (k *RSAKey) DecryptBase64(ciphertext string) ([]byte, error)

decrypts a base64 encoded encrypted string

func (*RSAKey) DecryptUnpack

func (k *RSAKey) DecryptUnpack(cipherData []byte) ([]byte, error)

decrypts and unpacks a payload encrypted using the above algorithm

func (*RSAKey) EncryptPack

func (k *RSAKey) EncryptPack(data []byte) ([]byte, error)

compresses and encrypts the given data payload with AES, encrypts and prepends the 256 bit AES key to the encrypted result using the RSA key

func (*RSAKey) GetEncryptedPrivateKeyPEM

func (k *RSAKey) GetEncryptedPrivateKeyPEM(password []byte) (string, error)

returns the PEM encoded private key

func (*RSAKey) GetPrivateKeyPEM

func (k *RSAKey) GetPrivateKeyPEM() (string, error)

returns the PEM encoded private key

func (*RSAKey) GetPublicKeyPEM

func (k *RSAKey) GetPublicKeyPEM() (string, error)

returns the PEM encoded public key

func (*RSAKey) PublicKey

func (k *RSAKey) PublicKey() *RSAPublicKey

returns the encapsulated public key

type RSAPublicKey

type RSAPublicKey struct {

	// a key id used to identify the private key
	// required to decrypt ciphertext encrypted
	// using this public key.
	KeyID string
	// contains filtered or unexported fields
}

func NewPublicKeyFromFile

func NewPublicKeyFromFile(pemFilePath string) (*RSAPublicKey, error)

func NewPublicKeyFromPEM

func NewPublicKeyFromPEM(publicKeyPEM string) (*RSAPublicKey, error)

creates a new RSA key from PEM encoded data

func (*RSAPublicKey) Encrypt

func (k *RSAPublicKey) Encrypt(plaintext []byte) ([]byte, error)

encrypts plain text using an RSA public key

func (*RSAPublicKey) EncryptBase64

func (k *RSAPublicKey) EncryptBase64(plaintext []byte) (string, error)

encrypt plain text and return the cipher text as base64 encoded text

func (*RSAPublicKey) SetKeyID

func (k *RSAPublicKey) SetKeyID(keyID string)

sets the key id

Jump to

Keyboard shortcuts

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