crypto

package
v2.34.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 2 modules, 9 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// Base36Uint64Width is the maximum number of base36 characters needed to represent any uint64:
	// ceil(64 / log2(36)) = 13.
	Base36Uint64Width = 13

	// Base62Uint64Width is the maximum number of base62 characters needed to represent any uint64:
	// ceil(64 / log2(62)) = 11.
	Base62Uint64Width = 11
)

Variables

View Source
var (
	// Base36 encodes input as base36.
	Base36 = NewEncoder(36)
	// Base62 encodes input as base62.
	Base62 = NewEncoder(62)
)
View Source
var (
	// Base36Sha224 hashes input with sha224 and encodes the digest as lowercase base36.
	Base36Sha224 = Hasher{/* contains filtered or unexported fields */}
	// Base62Sha224 hashes input with sha224 and encodes the digest as lowercase base62.
	Base62Sha224 = Hasher{/* contains filtered or unexported fields */}
)

Functions

func Random256BitsString

func Random256BitsString() string

Random256BitsString is a convenience function for calling RandomBitsString(256). Callers that need a random string should use this function unless they have a very good reason to need a different amount of entropy.

func RandomBits

func RandomBits(bits int) []byte

RandomBits returns a random byte slice with at least the requested bits of entropy. Callers should avoid using a value less than 256 unless they have a very good reason.

func RandomBitsString

func RandomBitsString(bits int) string

RandomBitsString returns a random string with at least the requested bits of entropy. It uses RawURLEncoding to ensure we do not get / characters or trailing ='s.

Types

type Encoder

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

Encoder produces base-N encodings of byte slices and uint64s.

func NewEncoder

func NewEncoder(base int) Encoder

NewEncoder returns an Encoder for the given base.

func (Encoder) Bytes

func (e Encoder) Bytes(b []byte) string

Bytes returns the base-N encoding of b. Leading zero bytes in b are dropped; use Encoder.BytesPad to preserve them.

func (Encoder) BytesPad

func (e Encoder) BytesPad(b []byte) string

BytesPad returns the base-N encoding of b, with one pad character prepended for each leading zero byte in b. An empty or all-zero b is encoded as a string of len(b) pad characters.

func (Encoder) Int

func (e Encoder) Int(v uint64) string

Int returns the base-N encoding of v's big-endian byte representation. The output is variable-length, use Encoder.IntPad for fixed-length.

func (Encoder) IntPad

func (e Encoder) IntPad(v uint64, width int) string

IntPad returns the base-N encoding of v's big-endian byte representation, left-zero-padded to width characters.

type Hasher

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

Hasher computes sha224(input) and encodes the digest with its embedded encoder.

func (Hasher) Bytes

func (h Hasher) Bytes(b []byte) string

Bytes calculates the sha224 hash of b and returns its base-N encoding. Leading zero bytes in the digest are dropped; use Hasher.BytesPad to preserve them.

func (Hasher) BytesPad

func (h Hasher) BytesPad(b []byte) string

BytesPad calculates the sha224 hash of b and returns its base-N encoding, with one pad character prepended for each leading zero byte in the digest.

func (Hasher) String

func (h Hasher) String(s string) string

String calculates the sha224 hash of s and returns its base-N encoding. Leading zero bytes in the digest are dropped; use Hasher.StringPad to preserve them.

func (Hasher) StringPad

func (h Hasher) StringPad(s string) string

StringPad calculates the sha224 hash of s and returns its base-N encoding, with one pad character prepended for each leading zero byte in the digest.

Jump to

Keyboard shortcuts

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