encoder

package
v0.0.0-...-3b54ddd Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataToLarge     = errors.New("message too long for RSA public key size")
	ErrDataLen         = errors.New("data length error")
	ErrDataBroken      = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch = errors.New("data is not encrypted by the private key")
	ErrDecryption      = errors.New("decryption error")
	ErrPublicKey       = errors.New("get public key error")
	ErrPrivateKey      = errors.New("get private key error")
)

below code from github.com/qyxing/ostar

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesEcbDecrypt

func AesEcbDecrypt(crypted, key []byte) ([]byte, error)

func AesEcbEncrypt

func AesEcbEncrypt(origData, key []byte) ([]byte, error)

////////////////////////////////////////////////////////////// example: data, err := aes.AesEncrypt([]byte(str), []byte(AES_KEY))

if err != nil {
	fmt.Println(err)
}

hexdata := hex.EncodeToString(data) fmt.Println(hex.EncodeToString(data)) data, err = hex.DecodeString(hexdata)

if err != nil {
	fmt.Println(err)
}

fmt.Println(string(data))

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

AES-128。key长度:16, 24, 32 bytes 对应 AES-128, AES-192, AES-256

func Base64Decode

func Base64Decode(src []byte) (out []byte)

func Base64DecodeString

func Base64DecodeString(src string) (out string)

在go中, 如果解码的字符串缺少最后的=号, 将不能解码, 所以先填补缺少的=

func Base64Encode

func Base64Encode(src []byte) []byte

func Base64EncodeString

func Base64EncodeString(src string) (out string)

func DesDecrypt

func DesDecrypt(crypted, key []byte) ([]byte, error)

func DesEncrypt

func DesEncrypt(origData, key []byte) ([]byte, error)

func Hash

func Hash(in []byte, hash crypto.Hash) (out []byte)

func HashString

func HashString(in string, hash crypto.Hash) (out string)

func Hmac

func Hmac(origin, key []byte, hash crypto.Hash) []byte

func Md5

func Md5(in []byte) (out []byte)

func Md5String

func Md5String(in string) (out string)

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func RsaPriDecrypt

func RsaPriDecrypt(origin, priKey []byte) (data []byte, err error)

func RsaPriEncrypt

func RsaPriEncrypt(origin, priKey []byte) (data []byte, err error)

func RsaPubDecrypt

func RsaPubDecrypt(origin, pubKey []byte) (data []byte, err error)

func RsaPubEncrypt

func RsaPubEncrypt(origin, pubKey []byte) (data []byte, err error)

func RsaSign

func RsaSign(origin, priKey []byte, hash crypto.Hash) ([]byte, error)

func RsaVerify

func RsaVerify(origin, sign, pubKey []byte, hash crypto.Hash) error

func Sha256

func Sha256(in string) string

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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