Documentation ¶
Overview ¶
Package cryptos 密码.
文本加密/解密,支持AES、DES,多用于配置文件密码加密.
密文格式: 加密方法(base64)
AES(NR501ySw4TYFc0dI8zERfA==) DES(2lz8gGSpYbA=)
AES安全性较高,DES密文较短.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/cryptos" ) func main() { password := "password" txt := cryptos.Encrypt("123", password, cryptos.DES) // fmt.Println(txt) fmt.Println(cryptos.IsEncrypt(txt)) fmt.Println(cryptos.Decrypt(txt, password)) }
Output: true 123 <nil>
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 ¶
Decrypt 解密.
str, _ := cryptos.Decrypt("AES(NR501ySw4TYFc0dI8zERfA==)", "password") fmt.Println(str) // 123
func Encrypt ¶
Encrypt 加密.
txt := cryptos.Encrypt("123", "password", cryptos.AES) fmt.Println(txt) // AES(NR501ySw4TYFc0dI8zERfA==)
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>
Types ¶
Click to show internal directories.
Click to hide internal directories.