Skip to content
Node: crypto, bcryptgithub.com/sahilkhaire/gox/crypto

RandomString

Overview ​

RandomString returns a URL-safe base64 string with roughly n bytes of entropy (uses n random bytes, encoded without padding).

Part of the crypto package — Node.js analog: crypto, bcrypt.

Signature ​

go
func RandomString(n int) (string, error)

Compare: Node.js · Standard Go · gox ​

js
// Typical crypto, bcrypt pattern in Node.js
go
b := make([]byte, n)
_, err := rand.Read(b)
go
import "github.com/sahilkhaire/gox/crypto"

token, err := crypto.RandomString(32)

Example ​

go
import "github.com/sahilkhaire/gox/crypto"

token, err := crypto.RandomString(32)

Tips ​

Import github.com/sahilkhaire/gox/crypto and call RandomString directly. See the comparison below for the standard library equivalent.

Standard library alternative ​

Use the standard library directly:

go
b := make([]byte, n)
_, err := rand.Read(b)

← Back to crypto package overview

MIT Licensed · Built for Node.js developers moving to Go