Documentation ¶
Index ¶
- type Cipher
- func NewAESCipher(aesKey []byte) (*Cipher, error)
- func NewHMACSHA256Signer(aesKey []byte) (*Cipher, error)
- func NewRSACipher(privateKeyPem []byte) (*Cipher, error)
- func NewRSAEncryptOnlyCipher(publicKeypem []byte) (*Cipher, error)
- func NewRSASigner(privateKeyPem []byte) (*Cipher, error)
- func NewRSASignerVerifyOnly(publicKeypem []byte) (*Cipher, error)
- func (c Cipher) Decrypt(ciphertext []byte, dst interface{}) error
- func (c Cipher) DecryptString(ciphertext string, dst interface{}) error
- func (c Cipher) Encrypt(data interface{}) ([]byte, error)
- func (c Cipher) EncryptToString(data interface{}) (string, error)
- func (c Cipher) Sign(data interface{}) (signature string, bytesSigned []byte, err error)
- func (c Cipher) SignToString(data interface{}) (signature string, signedData string, err error)
- func (c Cipher) Verify(data interface{}, signature string) error
- func (c Cipher) VerifyAndLoad(signedData []byte, signature string, dst interface{}) error
- func (c Cipher) VerifyStringAndLoad(signedData string, signature string, dst interface{}) error
- type Compressor
- type Encrypter
- type Serializer
- type Signer
- type StringEncoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cipher ¶
type Cipher struct { // Serializer performs the first (or final) step of converting the input data to a []byte Serializer Serializer // Compressor is an optional component to compress the output (or input) of the Serializer. Compressor Compressor // Encrypter controls the encryption and decryption steps. Encrypter Encrypter // Signer controls the signing and verification steps. Signer Signer // StringEncoder must implement the StringEncoder interface // // There are many Encodings from "encoding/base32", "encoding/base64", // and "encoding/hex" which satisfy the StringEncoder interface StringEncoder StringEncoder }
func NewAESCipher ¶
func NewHMACSHA256Signer ¶
func NewRSACipher ¶
func NewRSAEncryptOnlyCipher ¶
func NewRSASigner ¶
func NewRSASignerVerifyOnly ¶
func (Cipher) DecryptString ¶
func (Cipher) EncryptToString ¶
func (Cipher) SignToString ¶
func (Cipher) VerifyAndLoad ¶
type Compressor ¶
The Compressor type compresses and decompresses []byte.
var ( Zlib Compressor = ZlibCompression(zlib.BestCompression) Gzip Compressor = GzipCompression(gzip.BestCompression) )
func GzipCompression ¶
func GzipCompression(level int) Compressor
func ZlibCompression ¶
func ZlibCompression(level int) Compressor
type Encrypter ¶
type Encrypter interface { Encrypt(plaintext []byte) ([]byte, error) Decrypt(ciphertext []byte) ([]byte, error) }
The Encrypter type encrypts and decrypts []byte.
Encrypters must know how to find the key they require as the key is not passed in as a function argument.
func RSAEncryptOnly ¶
RSAEncryptOnly will return an asymmetric Encrypter using RSA which can only Encrypt.
type Serializer ¶
type Serializer interface { Serialize(interface{}) ([]byte, error) Deserialize([]byte, interface{}) error }
The Serializer type serializes and deserializes the input data types to a []byte.
var ( String Serializer = stringSerializer{} Bytes Serializer = bytesSerializer{} JSON Serializer = jsonSerializer{} Gob Serializer = gobSerializer{} )
type Signer ¶
type Signer interface { Sign(data []byte) ([]byte, error) Verify(data []byte, signature []byte) error }
The Signer type signs and verify []byte.
Signers must know how to find the key they require as the key is not passed in as a function argument.
func HMACSHA256 ¶
HMACSHA256 will return a Signer which uses HMAC-SHA-256
func RSAVerifyOnly ¶
RSAVerifyOnly will return an asymmetric Encrypter using RSA which can only Verify, but not sign.
type StringEncoder ¶
type StringEncoder interface { EncodeToString(src []byte) string DecodeString(s string) ([]byte, error) }
The StringEncoder type encodes and decodes binary data to a string.
var DefaultStringEncoder StringEncoder = base64.RawURLEncoding
DefaultStringEncoder is the default encoder to use for Cipher.EncryptToString() and Cipher.DecryptString().
This value is filled into the Cipher struct by the NewXXXCipher functions.