gm

package
v0.0.0-...-bd0efcb Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockSize = 16
	KeySize   = 16
)

Variables

This section is empty.

Functions

func NewCipher

func NewCipher(key []byte) (cipher.Block, error)

Types

type EncryptionService

type EncryptionService struct {
	Key []byte
	Iv  []byte
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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