Documentation ¶
Index ¶
- Constants
- Variables
- func CutPadKey(key string, size int) string
- func Pkcs7Pad(data []byte, size int) []byte
- func Pkcs7Unpad(data []byte) []byte
- func Salt(chars, salt, src string) string
- func Unsalt(chars, salt, src string) string
- type Cryptor
- type Decryptor
- func NewAes128CBCDecryptor(secret string) Decryptor
- func NewAes128CFBDecryptor(secret string) Decryptor
- func NewAes192CBCDecryptor(secret string) Decryptor
- func NewAes192CFBDecryptor(secret string) Decryptor
- func NewAes256CBCDecryptor(secret string) Decryptor
- func NewAes256CFBDecryptor(secret string) Decryptor
- func NewAesCBCDecryptor(secret string, bits int) Decryptor
- func NewAesCFBDecryptor(secret string, bits int) Decryptor
- type Encryptor
- func NewAes128CBCEncryptor(secret string) Encryptor
- func NewAes128CFBEncryptor(secret string) Encryptor
- func NewAes192CBCEncryptor(secret string) Encryptor
- func NewAes192CFBEncryptor(secret string) Encryptor
- func NewAes256CBCEncryptor(secret string) Encryptor
- func NewAes256CFBEncryptor(secret string) Encryptor
- func NewAesCBCEncryptor(secret string, bits int) Encryptor
- func NewAesCFBEncryptor(secret string, bits int) Encryptor
- type Padder
- type Padding
- type Token
- type Tokener
Constants ¶
const (
SecretChars = str.Base64URL
)
Variables ¶
var ( ErrTokenLength = errors.New("invalid token length") ErrTokenTimestamp = errors.New("invalid token timestamp") )
Functions ¶
func CutPadKey ¶ added in v1.0.14
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 ¶
Pkcs7Pad returns the byte array passed as a parameter padded with bytes such that the new byte array will be an exact multiple of the expected block size. For example, if the expected block size is 8 bytes (e.g. PKCS #5) and that the initial byte array is:
[]byte{0x0A, 0x0B, 0x0C, 0x0D}
the returned array will be:
[]byte{0x0A, 0x0B, 0x0C, 0x0D, 0x04, 0x04, 0x04, 0x04}
The value of each octet of the padding is the size of the padding. If the array passed as a parameter is already an exact multiple of the block size, the original array will be padded with a full block.
func Pkcs7Unpad ¶
Pkcs7Unpad removes the padding of a given byte array, according to the same rules as described in the Pad function. For example if the byte array passed as a parameter is:
[]byte{0x0A, 0x0B, 0x0C, 0x0D, 0x04, 0x04, 0x04, 0x04}
the returned array will be:
[]byte{0x0A, 0x0B, 0x0C, 0x0D}
Types ¶
type Decryptor ¶ added in v1.0.23
type Decryptor interface { DecryptString(string) (string, error) DecryptBytes([]byte) ([]byte, error) }
func NewAes128CBCDecryptor ¶ added in v1.0.23
func NewAes128CFBDecryptor ¶ added in v1.0.23
func NewAes192CBCDecryptor ¶ added in v1.0.23
func NewAes192CFBDecryptor ¶ added in v1.0.23
func NewAes256CBCDecryptor ¶ added in v1.0.23
func NewAes256CFBDecryptor ¶ added in v1.0.23
func NewAesCBCDecryptor ¶ added in v1.0.23
func NewAesCFBDecryptor ¶ added in v1.0.23
type Encryptor ¶ added in v1.0.23
type Encryptor interface { EncryptString(string) (string, error) EncryptBytes([]byte) ([]byte, error) }
func NewAes128CBCEncryptor ¶ added in v1.0.23
func NewAes128CFBEncryptor ¶ added in v1.0.23
func NewAes192CBCEncryptor ¶ added in v1.0.23
func NewAes192CFBEncryptor ¶ added in v1.0.23
func NewAes256CBCEncryptor ¶ added in v1.0.23
func NewAes256CFBEncryptor ¶ added in v1.0.23
func NewAesCBCEncryptor ¶ added in v1.0.23
func NewAesCFBEncryptor ¶ added in v1.0.23
type Padder ¶ added in v1.0.23
type Padder int
Padder struct embeds attributes necessary for the padding calculation (e.g. block size). It implements the Padding interface.
type Padding ¶ added in v1.0.23
Padding interface defines functions Pad and Unpad implemented for PKCS #5 and PKCS #7 types of padding.
func NewPkcs5Padding ¶ added in v1.0.23
func NewPkcs5Padding() Padding
NewPkcs5Padding returns a PKCS5 padding type structure. The blocksize defaults to 8 bytes (64-bit). See https://tools.ietf.org/html/rfc2898 PKCS #5: Password-Based Cryptography. Specification Version 2.0
func NewPkcs7Padding ¶ added in v1.0.23
NewPkcs7Padding returns a PKCS7 padding type structure. The blocksize is passed as a parameter. See https://tools.ietf.org/html/rfc2315 PKCS #7: Cryptographic Message Syntax Version 1.5. For example the block size for AES is 16 bytes (128 bits).