Documentation ¶
Index ¶
- Constants
- func NewCipher(key []byte) (cipher.Block, error)
- type EncryptionService
- func (s *EncryptionService) Config(key []byte, iv []byte)
- func (s *EncryptionService) Decrypt(ciphertext []byte) ([]byte, error)
- func (s *EncryptionService) DecryptString(ciphertext string) ([]byte, error)
- func (s *EncryptionService) Encrypt(plaintext []byte) ([]byte, error)
- func (s *EncryptionService) EncryptToString(plaintext []byte) (string, error)
- func (s *EncryptionService) SetIV(iv []byte)
- func (s *EncryptionService) SetKey(key []byte)
- type KeySizeError
Constants ¶
View Source
const ( BlockSize = 16 KeySize = 16 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EncryptionService ¶
func (*EncryptionService) Config ¶
func (s *EncryptionService) Config(key []byte, iv []byte)
func (*EncryptionService) Decrypt ¶
func (s *EncryptionService) Decrypt(ciphertext []byte) ([]byte, error)
func (*EncryptionService) DecryptString ¶
func (s *EncryptionService) DecryptString(ciphertext string) ([]byte, error)
func (*EncryptionService) Encrypt ¶
func (s *EncryptionService) Encrypt(plaintext []byte) ([]byte, error)
use gm to encrypt text
encrypter := cipher.NewCBCEncrypter(c, data.iv)
result := make([]byte, len(data.out)) encrypter.CryptBlocks(result, util.PKCS5Padding(data.in, BlockSize)) fmt.Printf("encrypt result:%s\n", hex.EncodeToString(result)) if !bytes.Equal(result, data.out) { t.Error("encrypt result not equal expected") return }
func (*EncryptionService) EncryptToString ¶
func (s *EncryptionService) EncryptToString(plaintext []byte) (string, error)
func (*EncryptionService) SetIV ¶
func (s *EncryptionService) SetIV(iv []byte)
func (*EncryptionService) SetKey ¶
func (s *EncryptionService) SetKey(key []byte)
type KeySizeError ¶
type KeySizeError int
func (KeySizeError) Error ¶
func (k KeySizeError) Error() string
Click to show internal directories.
Click to hide internal directories.