libcrypto

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

A cryptography utilities for golang

Features

  • Compute a hash of a password using Pbkdf2 (sha256 and sha512)
  • Encrypt and decrypt data using AES-CBC

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptAesCbc

func DecryptAesCbc(key string, cipherText string) (string, error)

DecryptAesCbc returns a decrypted text.

key := "key..."
cipherText := "cipher text..."

// decrypt the cipher text
cipherText, err := DecryptAesCbc(key, cipherText)
if err != nil {
	panic(err)
}

func EncryptAesCbc

func EncryptAesCbc(key string, clearText string) (string, error)

EncryptAesCbc returns a cipher text.

saltSize := 16
salt, err := libcrypto.GenerateSalt(saltSize)
if err != nil {
	t.Errorf("Failed to generate salt: %v", err)
}

// compute a 256-bit password hash with salt and 100000 iterations
key := libcrypto.Pbkdf2Hash256("password", salt, 100000)

clearText := "test to encrypt"

// encrypt the clear text
cipherText, err := EncryptAesCbc(key, clearText)
if err != nil {
	panic(err)
}

func GenerateSalt

func GenerateSalt(size int) ([]byte, error)

GenerateSalt returns a random salt.

func PKCS5Padding

func PKCS5Padding(clearText []byte, blockSize int) []byte

PKCS5Padding returns a padded text.

func PKCS5Trimming

func PKCS5Trimming(encrypt []byte) []byte

PKCS5Trimming returns a encrypted bytes without padding.

func Pbkdf2Hash256

func Pbkdf2Hash256(password string, salt []byte, iter int) string

Pbkdf2Hash256 returns a PBKDF2-SHA256 hash of the given password.

saltSize := 16
salt, err := GenerateSalt(saltSize)
if err != nil {
	panic(err)
}

// compute a 256-bit password hash with salt and 100000 iterations
hash := Pbkdf2Hash256("password", salt, 100000)

func Pbkdf2Hash512

func Pbkdf2Hash512(password string, salt []byte, iter int) string

Pbkdf2Hash512 returns a PBKDF2-SHA512 hash of the given password.

saltSize := 16
salt, err := GenerateSalt(saltSize)
if err != nil {
	panic(err)
}

// compute a 512-bit password hash with salt and 100000 iterations
hash := Pbkdf2Hash512("password", salt, 100000)

func Pbkdf2Match256

func Pbkdf2Match256(hash string, password string, salt []byte, iter int) bool

Pbkdf2Match256 validates the given password against the given hash (256-bit hash).

func Pbkdf2Match512

func Pbkdf2Match512(hash string, password string, salt []byte, iter int) bool

Pbkdf2Match512 validates the given password against the given hash (512-bit hash).

Types

This section is empty.

Jump to

Keyboard shortcuts

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