libcrypto

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MIT Imports: 1 Imported by: 1

README

A cryptography utilities for golang

Installation

This library requires Go 1.17 or newer; add it to your go.mod with:

go get github.com/MedzikUser/libcrypto-go

Examples

Hashing using PBKDF2

// example data
password := "very secret passphrase"
salt := []byte("password salt")
iterations := 100

// PBKDF2 with SHA256 algorithm
hash256 := hash.Pbkdf2Hash256(password, salt, iterations)

// PBKDF2 with SHA512 algorithm
hash512 := hash.Pbkdf2Hash512(password, salt, iterations)

AES Encryption

// example data
clearText := "hello world"
password := "very secret passphrase"
passwordSalt := []byte("password salt")
passwordIterations := 100

// compute a 256-bit AES key from the password
key := hash.Pbkdf2Hash256(password, passwordSalt, passwordIterations)

// encrypt the clear text using AES-CBC algorithm
cipherText, err := aes.EncryptAesCbc(key, clearText)

// decrypt the cipher text using AES-CBC algorithm
decryptedText, err := aes.EncryptAesCbc(key, cipherText)

RSA Signing

// example data
message := "hello world"

// generate a new RSA key pair
privateKey, publicKey, err := rsa.GenerateKey(2048)

// sign the message
signature, err := rsa.Sign(privateKey, message)

// verify the signature
err = rsa.ValidateSign(publicKey, message, signature)

RSA Encryption

// example data
clearText := "hello world"
label := "some label"

// generate a new RSA key pair
privateKey, publicKey, err := rsa.GenerateKey(2048)

// encrypt the clear text using RSA-OAEP algorithm
cipherText, err := rsa.Encrypt(publicKey, clearText, label)

// decrypt the cipher text using RSA-OAEP algorithm
decryptedText, err := rsa.Decrypt(privateKey, cipherText, label)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSalt

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

GenerateSalt returns a random salt.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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