cpt

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SecretChars = str.Base64URL
)

Variables

View Source
var (
	ErrTokenLength    = errors.New("invalid token length")
	ErrTokenTimestamp = errors.New("invalid token timestamp")
)

Functions

func CutPadKey added in v1.0.14

func CutPadKey(key string, size int) string

CutPadKey cut key if key's length is greater than 'size', or pad key with space if key's length is smaller than 'size'.

func Pkcs7Pad

func Pkcs7Pad(data []byte, size int) []byte

func Pkcs7Unpad

func Pkcs7Unpad(data []byte) []byte

func Salt

func Salt(chars, salt, src string) string

func Unsalt

func Unsalt(chars, salt, src string) string

Types

type AesCBC

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

func NewAesCBC

func NewAesCBC(key string, iv ...string) *AesCBC

func (*AesCBC) DecryptData

func (ac *AesCBC) DecryptData(src []byte) (des []byte, err error)

func (*AesCBC) DecryptString

func (ac *AesCBC) DecryptString(src string) (string, error)

func (*AesCBC) EncryptData

func (ac *AesCBC) EncryptData(src []byte) (des []byte, err error)

func (*AesCBC) EncryptString

func (ac *AesCBC) EncryptString(src string) (string, error)

func (*AesCBC) SetIV

func (ac *AesCBC) SetIV(iv string)

func (*AesCBC) SetKey

func (ac *AesCBC) SetKey(key string)

type AesCFB

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

func NewAesCFB

func NewAesCFB(key string, iv ...string) *AesCFB

func (*AesCFB) DecryptData

func (ac *AesCFB) DecryptData(src []byte) ([]byte, error)

func (*AesCFB) DecryptString

func (ac *AesCFB) DecryptString(src string) (string, error)

func (*AesCFB) EncryptData

func (ac *AesCFB) EncryptData(src []byte) ([]byte, error)

func (*AesCFB) EncryptString

func (ac *AesCFB) EncryptString(src string) (string, error)

func (*AesCFB) SetIV

func (ac *AesCFB) SetIV(iv string)

func (*AesCFB) SetKey

func (ac *AesCFB) SetKey(key string)

type Cryptor

type Cryptor interface {
	SetKey(key string)
	SetIV(iv string)
	EncryptString(str string) (string, error)
	DecryptString(str string) (string, error)
	EncryptData(data []byte) ([]byte, error)
	DecryptData(data []byte) ([]byte, error)
}

type Token

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

func NewToken

func NewToken() *Token

func ParseToken

func ParseToken(token string) (t *Token, err error)

func (*Token) Refresh

func (t *Token) Refresh()

func (*Token) Salt

func (t *Token) Salt() string

func (*Token) Secret

func (t *Token) Secret() string

func (*Token) String

func (t *Token) String() string

func (*Token) Timestamp

func (t *Token) Timestamp() time.Time

func (*Token) Token

func (t *Token) Token() string

type Tokener

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

func NewTokener

func NewTokener(saltLength, secretLength int) *Tokener

func (*Tokener) NewToken

func (tr *Tokener) NewToken(secret ...string) *Token

func (*Tokener) ParseToken

func (tr *Tokener) ParseToken(token string) (*Token, error)

Jump to

Keyboard shortcuts

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