Documentation ¶
Index ¶
- Constants
- func Equal(a, b []byte) bool
- func HashSum(h func() hash.Hash, data []byte) []byte
- func HmacSum(h func() hash.Hash, key, data []byte) []byte
- func Rand(b []byte)
- func RandN(size int) []byte
- func SHA256Hmac(key, data []byte) []byte
- func SHA256Sum(data []byte) []byte
- type Rotating
- type RotatingBytes
- type RotatingStr
Constants ¶
View Source
const Version = "3.0.0"
Version -
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
Equal compares two []byte for equality without leaking timing information.
fmt.Println(crypto.Equal([]byte("123"), []byte("123"))) fmt.Println(crypto.Equal([]byte("123"), []byte("1234")))
func HashSum ¶
HashSum returns hash result by given hash function and data
fmt.Println(crypto.HashSum(md5.New, []byte("hello"))) fmt.Println(crypto.HashSum(sha256.New, []byte("hello")))
func HmacSum ¶
HmacSum returns Keyed-Hash result by given hash function, key and data
fmt.Println(crypto.HmacSum(md5.New, []byte("my key"), []byte("hello"))) fmt.Println(crypto.HmacSum(sha256.New, []byte("my key"), []byte("hello")))
func SHA256Hmac ¶
SHA256Hmac returns SHA256 Keyed-Hash result by given key and data
fmt.Println(crypto.SHA256Hmac([]byte("my key"), []byte("hello")))
Types ¶
type Rotating ¶
type Rotating []interface{}
Rotating is used to verify data through a rotating credential system, in which new server keys can be added and old ones removed regularly, without invalidating client credentials.
var err error var claims josejwt.Claims index := Rotating(keys).Verify(func(key interface{}) bool { if err = jwtToken.Validate(key, method); err == nil { claims = jwtToken.Claims() return true } return false })
Click to show internal directories.
Click to hide internal directories.