strutil

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

Strutil

A collection of helper functions to deal with string encoding/decoding, generation.

Feel free to add new functions or improve the existing code.

Install

go get github.com/iconimpact/go-core/strutil

Usage and Examples

strutil.Encrypt encrypts data using 256-bit AES-GCM.

strutil.Decrypt decrypts data using 256-bit AES-GCM.

strutil.Random generates a NOT SECURE! random string of defined length.

strutil.RandomSecure generates a SECURELY random string of defined length and type: alpha, number, alpha-numeric

strutil.Hash generates a hash of data using HMAC-SHA-512/256.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(encryptedText string, key string) (string, error)

Decrypt decrypts data using 256-bit AES-GCM. Returned string is empty on error

func Encrypt

func Encrypt(text string, key string) (string, error)

Encrypt encrypts data using 256-bit AES-GCM. Needs a 256 bit key (32 characters) or it fails Returned string is empty on error

func Hash

func Hash(text string, description string) string

Hash generates a hash of data using HMAC-SHA-512/256 and adds the description text as HMAC "key" to get different hashes for different purposes. This function is NOT SECURE ENOUGH for securely hashing normal user-entered passwords, use HashPassword instead!

func Random

func Random(n int) string

Random generates a NOT SECURE! random string of defined length The result is NOT SECURE but fast because it uses the time as seed taken from https://goo.gl/9GBmNN

func RandomSecure

func RandomSecure(strSize int, randType string) string

RandomSecure returns a SECURELY generated random string randType can be:

  • "alpha" for range A-Z a-z
  • "number" for range 0-9, returns string number with leading 0s
  • "pin" for range 1-9 A-Z without O, I letters
  • any other value for A-Z a-z 0-9

It will panic in the super rare case of an issue to avoid any cascading security issues orients on https://goo.gl/kK987i and https://goo.gl/NRrS7y

Types

This section is empty.

Jump to

Keyboard shortcuts

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