crypto

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

README

Crypto

Crypto package implements state-of-the-art hashing algorithms and elliptic helper functions.

Usage
Random string
package main

import "github.com/infiniteloopcloud/crypto"

func main() {
	// Generates a cryptographically secure random string
	crypto.RandomString(10)
}
Hashing
package main

import "github.com/infiniteloopcloud/crypto"

func main() {
	// Get a crypto algorithm, options: Argon2id
	alg, _ := crypto.Get(crypto.Argon2id)
	
	// Generate salt and hash a string
	salt := crypto.RandomString(10)
	hash := alg.Hash("data", salt)
	
	// Check data against the hash
	alg.Verify("data", salt, hash)
}
Token generation
package main

import (
	"fmt"
	"github.com/infiniteloopcloud/crypto"
)

func main() {
	// Get a crypto algorithm, options: Argon2id
	alg, _ := crypto.Get(crypto.Argon2id)

	// Generate cryptographically secure token
	token := alg.GenerateToken("salt")
	fmt.Println(token)
}
Elliptic curve helpers
  • MarshalECPublicKey accept an ecdsa.PublicKey and marshal it to a compressed shareable format
  • UnmarshalECPublicKey accept a compressed format and parse to an ecdsa.PublicKey

Documentation

Overview

Package crypto provides cryptographic solutions for the user package. The main responsibility to define one or more hashing methods to store passwords and other sensitive data securely.

Index

Constants

View Source
const (
	// Argon2id defines a type for argon2 hashing as enum
	Argon2id uint8 = iota
)
View Source
const (
	// DefaultSaltLength defines the default length when salt generation happening
	DefaultSaltLength = 18
)

Variables

This section is empty.

Functions

func MarshalECPublicKey

func MarshalECPublicKey(publicKey ecdsa.PublicKey) string

MarshalECPublicKey accept an ecdsa.PublicKey and marshal it to a compressed shareable format

func RandomString

func RandomString(n int) string

RandomString generates random bytes and returns as string

func UnmarshalECPublicKey

func UnmarshalECPublicKey(compressed string) (ecdsa.PublicKey, error)

UnmarshalECPublicKey accept a compressed format and parse to an ecdsa.PublicKey

Types

type Descriptor

type Descriptor interface {
	// Hash should be able to do a hashing on an arbitrary string
	Hash(str, salt string) string

	// Verify should be able to verify a previously created hash
	// by compering with the arbitrary string
	Verify(str, salt, hash string) error

	// GenerateToken should be able to generate a token
	// which hardened with the hashing algorithm
	GenerateToken(tokenSalt string) string
}

Descriptor defines what a hashing implementation should be able to do

func Get

func Get(typ uint8) (Descriptor, error)

Get will return a hash algorithm for use, or returns error

Jump to

Keyboard shortcuts

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