cryptos

package
v0.4.28 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cryptos 加密.

加密、解密,AES、DES,多用于配置文件密码加密.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrUnpaddingLength = errors.New("invalid unpadding length")
	ErrNoEncrypt       = errors.New("no encrypt")
)

Functions

func Decrypt

func Decrypt(src, key string) (string, error)

Decrypt 解密.

func Encrypt

func Encrypt(str, key string, cipher Cipher) string

Encrypt 加密.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/cryptos"
)

func main() {
	key := "key"
	str := cryptos.Encrypt("aaa", key, cryptos.AES)
	fmt.Println(cryptos.Decrypt(str, key))

	str = cryptos.Encrypt("AAA", key, cryptos.DES)
	fmt.Println(cryptos.Decrypt(str, key))

}
Output:

aaa <nil>
AAA <nil>

func IsEncrypt

func IsEncrypt(str string) bool

IsEncrypt 是否加密.

func Padding

func Padding(str string, blockSize int) []byte

func UnPadding

func UnPadding(cipherText []byte) (string, error)

Types

type Cipher

type Cipher int
const (
	AES Cipher = iota
	DES
)

func Parse

func Parse(str string) (src []byte, cipher Cipher, err error)

nolint: nonamedreturns

func (Cipher) Block

func (p Cipher) Block(key string) cipher.Block

func (Cipher) String

func (p Cipher) String() string

func (Cipher) Stringify

func (p Cipher) Stringify(data []byte) string

Jump to

Keyboard shortcuts

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