random_encrypt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

random_encrypt

基于openssl加密

仅使用了 AES-128-CBC
根据时间戳所在的时间区间,时区信息计算加密的key,iv
为每个key设置有效时间(默认5秒,冗余2秒),在不同的时间区间(左包右闭),相同文本加密后的字符串不同
默认时区为东八区,加密端和解密端通过统一时区对齐时间,避免不同时区,同时间段,加密后的密文不同,导致无法解密
在使用时,必须自定义盐值,不能为空。if e.salt == "" { panic("the salt can not be empty") }
Encrypt函数返回 (加密后字符串,key,iv,加密时使用的时间戳) 供解密失败后备查。

Install

go get -u github.com/siburuxue/go_random_encrypt

示例代码:

config := map[string]interface{}{"salt": "salt"}
e := random_encrypt.NewRandomEncrypt(config)
s, key, iv, timestamp := e.Encrypt("hello world")
fmt.Println(s)
fmt.Println(key)
fmt.Println(iv)
fmt.Println(timestamp)
t := e.Decrypt(s)
fmt.Println(t)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RandomEncrypt

type RandomEncrypt struct {
	// contains filtered or unexported fields
}

func NewRandomEncrypt

func NewRandomEncrypt(config map[string]interface{}) RandomEncrypt

NewRandomEncrypt 初始化参数 map[string]interface{}{"salt": "salt", "offset": 10, "timeInterval": 7, "secondRedundancy": 3}

func (*RandomEncrypt) Config

func (e *RandomEncrypt) Config(config map[string]interface{}) *RandomEncrypt

Config 自定义设置参数 map[string]interface{}{"salt": "salt", "offset": 10, "timeInterval": 7, "secondRedundancy": 3}

func (*RandomEncrypt) Decrypt

func (e *RandomEncrypt) Decrypt(str string) string

func (*RandomEncrypt) DecryptByKeyIv

func (e *RandomEncrypt) DecryptByKeyIv(str string, key string, iv string) (string, error)

func (*RandomEncrypt) DoDecrypt

func (e *RandomEncrypt) DoDecrypt(str string, timestamp int64) (string, error)

func (*RandomEncrypt) Encrypt

func (e *RandomEncrypt) Encrypt(str string) (string, string, string, int64)

func (*RandomEncrypt) SetSalt

func (e *RandomEncrypt) SetSalt(salt string) *RandomEncrypt

SetSalt 自定义盐值 加密时不能为空

func (*RandomEncrypt) SetSecondRedundancy

func (e *RandomEncrypt) SetSecondRedundancy(secondRedundancy int64) *RandomEncrypt

SetSecondRedundancy 自定义跨区间 冗余秒数 默认2秒

func (*RandomEncrypt) SetTimeInterval

func (e *RandomEncrypt) SetTimeInterval(timeInterval int64) *RandomEncrypt

SetTimeInterval 自定义加密key有效时间 默认5秒

func (*RandomEncrypt) SetTimezoneOffset

func (e *RandomEncrypt) SetTimezoneOffset(offset int64) *RandomEncrypt

SetTimezoneOffset 自定义对齐时区 默认东八区

Jump to

Keyboard shortcuts

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