crypto

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAuthKey  = errors.New("Invalid authKey")
	ErrInvalidPassword = errors.New("Invalid password")
)

Encrypt/decrypt errors

Functions

This section is empty.

Types

type DataRequest

type DataRequest struct {
	Data string `json:"data"`
}

DataRequest contains data to be encrypted/decrypted

type DataResponse

type DataResponse struct {
	Data string `json:"data"`
}

DataResponse contains the encrypted/decrypted data

type InitRequest

type InitRequest struct {
	Name     string `json:"name"`
	Password string `json:"pwd"`
}

InitRequest initializes the decryption server with the given password

type InitResponse

type InitResponse struct {
	AuthKey string `json:"auth"`
}

InitResponse returns the AuthKey. This is a string to validate the decryption password

type LoginRequest

type LoginRequest struct {
	Password string `json:"pwd"`
	AuthKey  string `json:"auth"`
	Name     string `json:"name"`
}

LoginRequest sends the password and the authkey to the serevr to validate

type LoginResponse

type LoginResponse struct {
	Ok bool `json:"ok"`
}

LoginResponse returns the result of login password validation

type NameRequest

type NameRequest struct {
}

NameRequest requests the name of the server

type NameResponse

type NameResponse struct {
	Name string `json:"name"`
}

NameResponse contains the name of the server

type PingRequest

type PingRequest struct{}

PingRequest is ti check connection status and extend idle timeout

type PingResponse

type PingResponse struct{}

PingResponse is empty

type RequestProcessor

type RequestProcessor struct {
	Name string
	// contains filtered or unexported fields
}

RequestProcessor is created after a successful login. It implements a simple RPC protocol betwee the agent and a client using the agent to encrypt/decrypt data

func NewRequestProcessor

func NewRequestProcessor(server Server, pingFunc func(), name string) RequestProcessor

NewRequestProcessor return a new RequestProcessor object using the given server

func (*RequestProcessor) Decrypt

func (s *RequestProcessor) Decrypt(req DataRequest, response *DataResponse) error

Decrypt a block of data

func (*RequestProcessor) Encrypt

func (s *RequestProcessor) Encrypt(req DataRequest, response *DataResponse) error

Encrypt a block of data

func (*RequestProcessor) GetName

func (s *RequestProcessor) GetName(req NameRequest, response *NameResponse) error

GetName returns the name of the server

func (*RequestProcessor) Init

func (s *RequestProcessor) Init(req InitRequest, response *InitResponse) error

Init initializes the processor with a password

func (*RequestProcessor) Login

func (s *RequestProcessor) Login(req LoginRequest, response *LoginResponse) error

Login validates the password and sets up the encryption server

func (*RequestProcessor) Ping

func (s *RequestProcessor) Ping(req PingRequest, response *PingResponse) error

Ping calls the ping function

type Server

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

Server keeps all the information necessary to encrypt/decrypt data

func InitServer

func InitServer(password string) (Server, error)

InitServer creates a new encrypt/decrypt server using the given password. It returns the server containing a key and salt

func NewServer

func NewServer(password, authkey string) (Server, error)

NewServer returns a new server with the given password and authorization key. If the password does not validate, returns error

func (Server) Decrypt

func (s Server) Decrypt(in []byte) ([]byte, error)

Decrypt the given data block using key

func (Server) Encrypt

func (s Server) Encrypt(in []byte) ([]byte, error)

Encrypt the given data block using key

func (Server) GetAuthKey

func (s Server) GetAuthKey() (string, error)

GetAuthKey returns a string that can be used for password validation. It is:

salt iv enc(randombytes hmac)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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