encrypt

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	Letter = iota
	Digital
	Underline
	Characters
)
View Source
const (
	SHA1 = iota
	SHA256
	SHA512
)

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(src string) (result string)

func Base64EncodeByte

func Base64EncodeByte(src []byte) string

func Base64EncodeString

func Base64EncodeString(src string) string

func CheckPassword added in v0.0.7

func CheckPassword(pw string, flag Flag, minLen int, maxLen ...int) bool

CheckPassword checks if the actual element of the password matches the expected flag.

Example
fmt.Println(CheckPassword("A", N|L_OR_U, 2))
fmt.Println(CheckPassword("a", N|L_OR_U, 2))
fmt.Println(CheckPassword("1", N|L_OR_U, 2))
fmt.Println(CheckPassword("Aa", N|L_OR_U, 2))
fmt.Println(CheckPassword("A1", N|L_OR_U, 2))
fmt.Println(CheckPassword("a1", N|L_OR_U, 2))
fmt.Println(CheckPassword("Aa1", N|L_OR_U, 2))
fmt.Println(CheckPassword("AaBbCcDd", L|U, 6))
fmt.Println(CheckPassword("ABCD1234", N|U, 6))
fmt.Println(CheckPassword("ABCD1234", N|L_OR_U|U, 6))
fmt.Println(CheckPassword("ABCD1234", N|L_OR_U|L, 6))
fmt.Println(CheckPassword("abcd1234", N|L, 6, 7))
fmt.Println(CheckPassword("Aa123456", N|L_OR_U, 6, 8))
fmt.Println(CheckPassword("Aa@123456", Flag(1<<6)|N|L|U|S, 6, 16))
fmt.Println(CheckPassword("Aa123456语言", N|L|U, 6))
Output:

false
false
false
false
true
true
true
true
true
true
false
false
true
true
false

func SHA

func SHA(length int, content interface{}) (result string, err error)

SHA implements several hash functions, including sha1, sha256, and sha512. Meanwhile, SHA supports file hash. When content type is string, it indicates the address of the file.

Example
result, err := SHA(SHA1, []byte("hello world"))
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(result)
// output
// 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
Output:

func Score

func Score(pwd string) int

Types

type Flag added in v0.0.7

type Flag uint8

Flag denotes the expected or actual element of the password.

const (
	// N denotes the numerals.
	N Flag = 1 << 0
	// L_OR_U denotes the lowercase or uppercase letters.
	L_OR_U Flag = 1 << 1
	// L denotes the lowercase letters.
	L Flag = 1 << 2
	// U denotes the uppercase letters.
	U Flag = 1 << 3
	// S denotes the printable symbols found on the keyboard, except letters, numerals and spaces.
	S Flag = 1 << 4
)

type MessageDigest

type MessageDigest string

func MD5

func MD5(src interface{}) (md MessageDigest, err error)

func (MessageDigest) LowerCase16

func (md MessageDigest) LowerCase16() string

func (MessageDigest) UpperCase16

func (md MessageDigest) UpperCase16() string

func (MessageDigest) UpperCase32

func (md MessageDigest) UpperCase32() string

type Password

type Password struct {
	Value  string
	Length int
	// Regular : indicate password rules, allowing the
	// flowing four values([0, 1, 2, 3]).
	Regular []int
	// Score : [0,1,2,3,4] if crack time is less than
	// [10^2, 10^4, 10^6, 10^8, Infinity].
	// (useful for implementing a strength bar.)
	Score int
}

func Generate

func Generate(length int, regular ...int) *Password

Generate used to generate a random password based on the parameters, the default length of password is 8, the default password rule is composed of numbers and letters.

Jump to

Keyboard shortcuts

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