secure

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SALT_CHARS                = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	DEFAULT_PBKDF2_ITERATIONS = 310_000
)

Variables

This section is empty.

Functions

func GeneratePasswordHash

func GeneratePasswordHash(password, method string) string

GeneratePasswordHash

Hash a password with the given method and salt with a string of
the given length. The format of the string returned includes the method
that was used so that :func:`check_password_hash` can check the hash.

The format for the hashed string looks like this::

method$salt$hash

func GetEncryptionMethod

func GetEncryptionMethod(mode string, keySize int) string

func LoadRSAPrivateKey

func LoadRSAPrivateKey(data []byte) (*rsa.PrivateKey, error)

LoadRSAPrivateKey 解析私钥文件

func LoadRSAPrivateKeyFile

func LoadRSAPrivateKeyFile(pemFile string) (*rsa.PrivateKey, error)

func LoadRSAPublicKey

func LoadRSAPublicKey(data []byte) (*rsa.PublicKey, error)

LoadRSAPublicKey 解析公钥文件

func LoadRSAPublicKeyFile

func LoadRSAPublicKeyFile(pemFile string) (*rsa.PublicKey, error)

func MaxEncryptSize

func MaxEncryptSize(pubkey *rsa.PublicKey) int

MaxEncryptSize 最大加密内容大小

func PKCS5Pad

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

func PKCS5Unpad

func PKCS5Unpad(encrypted []byte) []byte

func SignAccessToken

func SignAccessToken(key string, args ...string) string

SignAccessToken 注册签名

func SignEncryptSignature

func SignEncryptSignature(method string, encrypt AESCryptor, priKey *rsa.PrivateKey) ([]byte, error)

SignEncryptSignature 签名

func VerifyEncryptSignature

func VerifyEncryptSignature(method string, signature []byte, encrypt AESCryptor, pubKey *rsa.PublicKey) error

VerifyEncryptSignature 校验签名

func VerifyPasswordHash

func VerifyPasswordHash(hashText, password string) bool

VerifyPasswordHash

check a password against a given salted and hashed password value.
In order to support unsalted legacy passwords this method supports
plain text passwords, md5 and sha1 hashes (both salted and unsalted).

Types

type AESCryptor

type AESCryptor interface {
	Key() ([]byte, []byte)
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)
}

AESCryptor https://en.wikipedia.org/wiki/Advanced_Encryption_Standard

func CreateAESCryptor

func CreateAESCryptor(method string) (AESCryptor, error)

CreateAESCryptor `method` is like "aes-128-cbc", "aes-256-ctr", "aes-192-gcm"

func NewAESCryptor

func NewAESCryptor(mode string, key, iv []byte) (AESCryptor, error)

Jump to

Keyboard shortcuts

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