Documentation
¶
Overview ¶
Package securerandom is a set of utilities for generating random data from the secure sources provided by the "crypto/rand" package. The package has the ability to generate bytes from securerandom data, as well as other data from those bytes. That includes numbers and Base64-encoded strings.
Example:
import ( "math/rand" "github.com/theckman/go-securerandom" ) ri64, err := securerandom.Int64() // secure-random data is unavailable if err != nil { /* handle err */ } rand.Seed(ri64)
You can also generate random base64 encoded strings from this package:
// generate string from 32 random bytes rStr, err := securerandom.Base64OfBytes(32) // secure-random data is unavailable if err != nil { /* handle err */ } fmt.Println(rStr) // assume your random string can only be 32 bytes long rStr, _ = securerandom.Base64InBytes(32) fmt.Println(rStr) // would print Base64 string with a length of 32
Index ¶
- Constants
- func Base64InBytes(max int) (string, error)
- func Base64OfBytes(n int) (string, error)
- func Bytes(n int) ([]byte, error)
- func Int16() (int16, error)
- func Int32() (int32, error)
- func Int64() (int64, error)
- func RandSource() (rand.Source, error)
- func URLBase64InBytes(max int) (string, error)
- func URLBase64OfBytes(n int) (string, error)
- func Uint16() (uint16, error)
- func Uint32() (uint32, error)
- func Uint64() (uint64, error)
Constants ¶
const PackageVersion = "0.1.1"
PackageVersion is the semantic version number of this package.
Variables ¶
This section is empty.
Functions ¶
func Base64InBytes ¶
Base64InBytes is a function that returns a randomized standard Base64 string. This does not use the URL encoding. It takes a single parameter that is the maximum possible length of the string, it will get as close as possible.
func Base64OfBytes ¶
Base64OfBytes is a function that returns a randomized standard Base64 string. This does not use the URL encoding. It takes a single parameter that is the number of bytes to used to generate the value.
func Bytes ¶
Bytes is a function that takes an integer and returns a slice of that length containing random bytes.
func Int16 ¶
Int16 is a function that returns a int16 generated by 'bitwise-or'ing 4 bytes from crypto/rand.Read().
func Int32 ¶
Int32 is a function that returns a int32 generated by 'bitwise-or'ing 4 bytes from crypto/rand.Read().
func Int64 ¶
Int64 is a function that returns a int64 generated by 'bitwise-or'ing 4 bytes from crypto/rand.Read().
func RandSource ¶
RandSource is a function that returns a Source from the "math/rand" package to be used to create a new pseudorandom generator. If this returns err != nil the value of the source is not suitable for use.
func URLBase64InBytes ¶
URLBase64InBytes is a function that returns a random URL encoded Base64 string. This does not use the URL encoding. It takes a single parameter that is the maximum possible length of the string, it will get as close as possible.
func URLBase64OfBytes ¶
URLBase64OfBytes is a function that returns a random URL encoded Base64 string. This is using URL encoding. It takes a single parameter that is the number of bytes to use to generate the value.
func Uint16 ¶
Uint16 is a function that returns a uint16 generated by 'bitwise-or'ing 4 bytes from crypto/rand.Read().
Types ¶
This section is empty.