crypto

package
v0.0.0-...-7aac46a Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 9 Imported by: 0

README

utils/crypto

Documentation

Overview

Crypto contains functionalities for secure and reliable encryption.

Index

Constants

View Source
const (
	RSADefaultC = 4096
)

Variables

View Source
var (
	RSALenError    error = errors.New("crypto: invalid rsa len.")
	RSAPow2Error   error = errors.New("crypto: not power of 2.")
	RSAInvalidFile error = errors.New("crypto: no public/private key in file.")
	RSAUnsupported error = errors.New("crypto: unsupported block type.")
)

Functions

func DecryptWith

func DecryptWith(privk *rsa.PrivateKey, ct []byte) ([]byte, error)

func EncryptWith

func EncryptWith(pubk *rsa.PublicKey, text []byte) ([]byte, error)

func LoadPrivateKey

func LoadPrivateKey(filename string) (*rsa.PrivateKey, error)

func LoadPublicKey

func LoadPublicKey(filename string) (*rsa.PublicKey, error)

func SignWith

func SignWith(privk *rsa.PrivateKey, text []byte) ([]byte, error)

func VerifySignatureWith

func VerifySignatureWith(pubk *rsa.PublicKey, text []byte, sig []byte) error

Types

type Crypto

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

Crypto is a struct containing all necessary information used during encryption/decryption. The struct members are not publicely exposed ( unimported ) and is only accessible via provided methods.

func NewCrypto

func NewCrypto() *Crypto

NewCrypto returns a new struct pointer of type `Crypto`. It uses default settings for n, r, p, keyLen respectively 16384, 8, 1, 32.

func NewCryptoFromArgs

func NewCryptoFromArgs(salt *[]byte, n int, r int, p int, keyLen int) *Crypto

NewCryptoFromArgs returns a new struct pointer of type `Crypto` and sets the internal according to given arguments. It is not neccessary to use this function directly as the default settings used by `NewCrypto()` is sufficient.

func (*Crypto) Decrypt

func (c *Crypto) Decrypt(input *[]byte) (dec string, err error)

Decrypt returns the decrypted data. Simlilar to `Encrypt`, error must be checked explicitely.

func (*Crypto) Encrypt

func (c *Crypto) Encrypt(input *[]byte) (enc string, err error)

Encrypt returns the encrypted data. It may fail, error should be explicitely checked to assure correctness.

func (*Crypto) SetSalt

func (c *Crypto) SetSalt(salt *[]byte)

SetSalt assigns internal salt value to a given `salt` byte array. It must be called on each new `Crypto` instance.

type RSA

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

func FromFile

func FromFile(f string) (*RSA, error)

func MakeRSA

func MakeRSA(c int) (ret *RSA, err error)

func NewRSA

func NewRSA(privk *rsa.PrivateKey, pubk *rsa.PublicKey) *RSA

func (*RSA) Decrypt

func (r *RSA) Decrypt(ct []byte) ([]byte, error)

func (*RSA) Encrypt

func (r *RSA) Encrypt(text []byte) ([]byte, error)

func (*RSA) GetPrivateKey

func (r *RSA) GetPrivateKey() *rsa.PrivateKey

func (*RSA) GetPublicKey

func (r *RSA) GetPublicKey() *rsa.PublicKey

func (*RSA) MarhsalPrivateKey

func (r *RSA) MarhsalPrivateKey() ([]byte, error)

func (*RSA) MarshalPublicKey

func (r *RSA) MarshalPublicKey() ([]byte, error)

func (*RSA) Save

func (r *RSA) Save() error

func (*RSA) Sign

func (r *RSA) Sign(text []byte) ([]byte, error)

func (*RSA) VerifySignature

func (r *RSA) VerifySignature(text []byte, sig []byte) error

Jump to

Keyboard shortcuts

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