secure

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: Apache-2.0 Imports: 27 Imported by: 1

Documentation

Overview

Copyright (c) 2018-2019 WING All Rights Reserved.

Author : yangping Email : youhei_yp@163.com

Prismy.No | Date | Modified by. | Description ------------------------------------------------------------------- 00001 2019/05/22 yangping New version -------------------------------------------------------------------

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(secretkey []byte, ciphertextb64 string) (string, error)

AESDecrypt using secret key to decrypt ciphertext

func AESEncrypt

func AESEncrypt(secretkey, original []byte) (string, error)

AESEncrypt using secret key to encrypt original data

func Base64ToByte

func Base64ToByte(ciphertext string) ([]byte, error)

ByteToBase64 decode base64 string to byte array

func ByteToBase64

func ByteToBase64(original []byte) string

ByteToBase64 encode byte array to base64 string

func DecodeBase64

func DecodeBase64(ciphertext string) (string, error)

DecodeBase64 decode from base64 string

func DecodeJwtKeyword

func DecodeJwtKeyword(keyword string) (string, string, string)

EncodeJwtKeyword decode account uuid, password and subject from jwt keyword string, NOTICE THAT this method split the keyword by ';' char!

func ECCHashSignB64

func ECCHashSignB64(hash []byte, prikeyb64 string) (string, error)

ECCHashSignB64 use ECC to sign hash data to base64 string by given origin private key text

func ECCHashVerifyB64

func ECCHashVerifyB64(hash []byte, pubkeyb64 string, rsb64 string) (bool, error)

ECCHashVerifyB64 use ECC public key and rs data to verify given hash data

func EncodeB64MD5

func EncodeB64MD5(original string) string

EncodeB64MD5 encode string to base64, and then encode by md5

func EncodeBase64

func EncodeBase64(original string) string

EncodeBase64 encode string by base64

func EncodeJwtKeyword

func EncodeJwtKeyword(uuid, pwd, subject string) string

EncodeJwtKeyword encode account uuid, password and subject string, NOTICE THAT this method joined the uuid, pwd and subject with ';' char!

func EncodeMD5

func EncodeMD5(original string) string

EncodeMD5 encode string by md5

func EncodeMD5B64

func EncodeMD5B64(original string) string

EncodeMD5B64 encode string to md5, and then encode by base64

func GenAESKey

func GenAESKey() string

GenAESKey generate AES key range chars in [0-9a-z]{16}

func GenCode

func GenCode() string

GenCode generate a code by using current nanosecond

func GenCodeFrom

func GenCodeFrom(src int64) string

GenCodeFrom generate a code from given int64 data

func GenECCPriKey

func GenECCPriKey(prikey string) (*ecdsa.PrivateKey, error)

GenECCPriKey generate a ECC private key by origin key text

func GenECCPriKeyB64

func GenECCPriKeyB64(prikeyb64 string) (*ecdsa.PrivateKey, error)

GenECCPriKeyB64 generate a ECC private key by base64 formated key text

func GenECCPubKey

func GenECCPubKey(pubkey string) (*ecdsa.PublicKey, error)

GenECCPubKey generate a ECC public key by origin key text

func GenECCPubKeyB64

func GenECCPubKeyB64(pubkeyb64 string) (*ecdsa.PublicKey, error)

GenECCPubKeyB64 generate a ECC public key by base64 formated key text

func GenECCShareKeys

func GenECCShareKeys(pub *ecdsa.PublicKey, priD *big.Int) (*big.Int, *big.Int)

GenECCShareKeys generate ECC shared keys by ECC public key and private digital signature

func GenEccShareKeysHash

func GenEccShareKeysHash(prikey, pubkey string) ([]byte, error)

GenEccShareKeysHash generate ECC share keys hash data by origin private and public key

func GenEccShareKeysHashB64

func GenEccShareKeysHashB64(prikeyb64, pubkeyb64 string) ([]byte, error)

GenEccShareKeysHashB64 generate ECC share keys hash data by base64 formated private and public key

func GenHash

func GenHash(src, salt string) (string, error)

GenHash hash the given source with salt

func GenJwtToken

func GenJwtToken(keyword, salt string, dur time.Duration) (string, error)

ObatinJwtToken generate a jwt token with keyword and salt string, the token will expired after the given duration

func GenLoginToken

func GenLoginToken(acc, pwd string) string

GenLoginToken generate a login token with account and password --------------------------------------------------------

account   password
    |- + -|
       |
    base64          current nanosecode
       |                    |
      md5                base64
       +------- "."---------|
                 |
              base64 => token

--------------------------------------------------------

func GenNonce added in v1.0.13

func GenNonce() string

GenNonce generate a random num than to string

func GenOAuthCode

func GenOAuthCode(length int, randomType string) (string, error)

GenOAuthCode generate a random OAuth code

func GenRSAKeys

func GenRSAKeys(bits int) (string, string, error)

GenRSAKeys generate RSA private and public keys in PKCS#1, ASN.1 DER form, and limit bits length of key cert.

func GenRSFromB2BI

func GenRSFromB2BI(sign []byte) (*big.Int, *big.Int)

GenRSFromB2BI generate R and S from sign data

func GenRandCode

func GenRandCode() string

GenRandCode generate a code by using current nanosecond and append random suffix

func GenRandCodeFrom

func GenRandCodeFrom(src int64) string

GenRandCodeFrom generate a code from given int64 data and append random suffix

func GenSalt

func GenSalt() (string, error)

GenSalt generates a random salt

func GenToken

func GenToken(original string) string

GenToken convert to lower string and encode by base64 -> md5

func GenUUID

func GenUUID() int64

GenUUID generate a new uuid in int64

func GenUUIDString

func GenUUIDString() string

GenUUIDString generate a new uuid in string

func HashByteThenBase64

func HashByteThenBase64(data []byte) string

HashByteThenBase64 hash byte array by sha256 and than to base64 string

func HashMD5

func HashMD5(original []byte) []byte

HashMD5 hash string by md5

func HashSHA256

func HashSHA256(original []byte) []byte

HashSHA256 hash byte array by sha256

func HashSHA256Hex added in v1.0.15

func HashSHA256Hex(original []byte) string

HashSHA256Hex hash byte array by sha256 then encode to hex

func HashSHA256String

func HashSHA256String(original string) []byte

HashSHA256String hash string by sha256

func HashThenBase64

func HashThenBase64(data string) string

HashThenBase64 hash string by sha256 and than to base64 string

func LoadRSAKey

func LoadRSAKey(filepath string, buffbits ...int) ([]byte, error)

LoadRSAKey load RSA or RSA2 private or public key content from the given pem file, and if input the beffer size, the bufbits must larger than pem file size by call GenRSAKeys to set bits.

func RSA2Sign added in v1.0.14

func RSA2Sign(prikey, original []byte) ([]byte, error)

RSA2Sign using RSA2 private key to make digital signature, the private key in PKCS#8, ASN.1 DER form.

func RSA2Sign4F added in v1.0.14

func RSA2Sign4F(prifile string, original []byte) ([]byte, error)

RSA2Sign4F using RSA2 private key file to make digital signature. the private key in PKCS#8, ASN.1 DER form.

func RSA2Sign4FB64 added in v1.0.14

func RSA2Sign4FB64(prifile string, original []byte) (string, error)

RSA2Sign4FB64 using RSA2 private key file to make digital signature, then format to base64 form, the private key in PKCS#8, ASN.1 DER form.

func RSA2SignB64 added in v1.0.14

func RSA2SignB64(prikey, original []byte) (string, error)

RSA2SignB64 using RSA2 private key file to make digital signature, then format to base64 form, the private key in PKCS#8, ASN.1 DER form.

func RSA2Verify added in v1.0.14

func RSA2Verify(pubkey, original, signature []byte) error

RSA2Verify using RSA2 public key to verify signatured data.

func RSA2Verify4F added in v1.0.14

func RSA2Verify4F(pubfile string, original, signature []byte) error

RSA2Verify4F using RSA2 public key to verify signatured data.

func RSADecrypt

func RSADecrypt(prikey, ciphertext []byte) ([]byte, error)

RSADecrypt using RSA private key to decrypt ciphertext.

func RSADecrypt4F added in v1.0.14

func RSADecrypt4F(prifile string, ciphertext []byte) ([]byte, error)

RSADecrypt4F using RSA private key file to decrypt ciphertext.

func RSAEncrypt

func RSAEncrypt(pubkey, original []byte) ([]byte, error)

RSAEncrypt using RSA public key to encrypt original data.

func RSAEncrypt4F added in v1.0.14

func RSAEncrypt4F(pubfile string, original []byte) ([]byte, error)

RSAEncrypt4F using RSA public key file to encrypt original data.

func RSAEncrypt4FB64 added in v1.0.14

func RSAEncrypt4FB64(pubfile string, original []byte) (string, error)

RSAEncrypt4FB64 using RSA public key file to encrypt original data, then format to base64 form.

func RSAEncryptB64 added in v1.0.14

func RSAEncryptB64(pubkey, original []byte) (string, error)

RSAEncryptB64 using RSA public key to encrypt original data, then format to base64 form.

func RSASign

func RSASign(prikey, original []byte) ([]byte, error)

RSASign using RSA private key to make digital signature, the private key in PKCS#1, ASN.1 DER form.

func RSASign4F added in v1.0.14

func RSASign4F(prifile string, original []byte) ([]byte, error)

RSASign4F using RSA private key file to make digital signature, the private key in PKCS#1, ASN.1 DER form.

func RSASign4FB64 added in v1.0.14

func RSASign4FB64(prifile string, original []byte) (string, error)

RSASign4FB64 using RSA private key file to make digital signature, then format to base64 form, the private key in PKCS#1, ASN.1 DER form.

func RSASignB64 added in v1.0.14

func RSASignB64(prikey, original []byte) (string, error)

RSASignB64 using RSA private key to make digital signature, then format to base64 form, the private key in PKCS#1, ASN.1 DER form.

func RSAVerify

func RSAVerify(pubkey, original, signature []byte) error

RSAVerify using RSA public key to verify signatured data.

func RSAVerify4F added in v1.0.14

func RSAVerify4F(pubfile string, original, signature []byte) error

RSAVerify4F using RSA public key file to verify signatured data.

func ToMD5Hex

func ToMD5Hex(input ...string) string

ToMd5Hex encode multi-input to md5 one string, it same as EncodeMD5 when input only one string.

func ViaJwtToken

func ViaJwtToken(signedToken, salt string) (string, error)

ViaLoginToken verify the encoded jwt token witch salt string

func ViaLoginToken

func ViaLoginToken(acc, pwd, token string, duration int64) (bool, error)

ViaLoginToken verify login token --------------------------------------------------------

      token => base64
                 |
       +------- "."---------|
      md5                base64
       |                    |
    base64          current nanosecode
       |
    |- + -|
account   password

--------------------------------------------------------

Types

type Claims

type Claims struct {
	Keyword string `json:"keyword"`
	jwt.StandardClaims
}

Claims jwt claims data

type SoleCoder

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

SoleCoder random coder to generate unique number code

func NewSoleCoder

func NewSoleCoder(data ...[]string) *SoleCoder

NewSoleCoder create SoleCoder and init with exist codes

func (*SoleCoder) Gen

func (c *SoleCoder) Gen(codelen int, times ...int) (string, error)

Gen generate a given length number code, it may throw a error when over the retry times

func (*SoleCoder) Remove

func (c *SoleCoder) Remove(code string)

Remove remove used sole code outof cache

Jump to

Keyboard shortcuts

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