VHtearCryptoutil

package module
v0.0.0-...-fd478f5 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 15 Imported by: 0

README

VHtearCryptoutil

VHtearCryptoutil is a Go (Golang) toolkit that provides various cryptographic and data manipulation functions. This package is designed to assist developers in implementing cryptography, encryption, decryption, and data manipulation easily and efficiently.

With VHtearCryptoutil, you can quickly integrate powerful cryptographic functions into your projects and efficiently manipulate data. This package is suitable for the development of applications that require data security, such as financial applications, sensitive data processing, and many others.

Key Features

  • AES-GCM encryption and decryption functions.
  • Calculation of checksums and data transformation using hashing.
  • Data processing in byte and hexadecimal formats.
  • And many other features.

Installation

You can easily install this package using the following command:

go get github.com/fckveza/VHtearCryptoutil
Extended usage
package main

import (
	"fmt"
	"github.com/fckveza/VHtearCryptoutil"
)

func main() {
	// Example of using GetSHA256Sum
	sha256Sum := VHtearCryptoutil.GetSHA256Sum("Hello, World!")
	fmt.Printf("SHA-256 Sum: %x\n", sha256Sum)

	// Example of using GenerateSharedSecret
	privateKey := []byte("private_key")
	publicKey := []byte("public_key")
	sharedSecret, err := VHtearCryptoutil.GenerateSharedSecret(privateKey, publicKey)
	if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Printf("Shared Secret: %x\n", sharedSecret)
	}

	// Example of using GenerateAAD
	aad := VHtearCryptoutil.GenerateAAD("example", "data", 42, 13, 7, 99)
	fmt.Printf("AAD: %x\n", aad)

	// Example of using DecryptWithAESGCM
	gcmKey := []byte("secret_key")
	nonce := []byte("unique_nonce")
	ciphertext := []byte("encrypted_data")
	message, err := VHtearCryptoutil.DecryptWithAESGCM(gcmKey, nonce, ciphertext, aad)
	if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Printf("Decrypted Message: %s\n", message)
	}

	// Example of using EncryptWithAESGCM
	dataToEncrypt := []byte("sensitive_data")
	ciphertext, err := VHtearCryptoutil.EncryptWithAESGCM(dataToEncrypt, gcmKey, nonce, aad)
	if err is not nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Printf("Encrypted Data: %x\n", ciphertext)
	}

	// Example of using EncHeaders
	headers := map[string]string{
		"Content-Type": "application/json",
		"Authorization": "Bearer token",
	}
	encodedHeaders := VHtearCryptoutil.EncHeaders(headers)
	fmt.Printf("Encoded Headers: %x\n", encodedHeaders)

	// Example of using Pad
	dataToPad := []byte("data_to_pad")
	paddedData := VHtearCryptoutil.Pad(dataToPad, 16)
	fmt.Printf("Padded Data: %x\n", paddedData)

	// Example of using Unpad
	unpaddedData, err := VHtearCryptoutil.Unpad(paddedData)
	if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Printf("Unpadded Data: %x\n", unpaddedData)
	}

	// Example of using CalculateChecksumAndTransform
	key := []byte("encryption_key")
	dataToTransform := []byte("data_to_transform")
	transformedData := VHtearCryptoutil.CalculateChecksumAndTransform(key, dataToTransform)
	fmt.Printf("Transformed Data: %x\n", transformedData)

	// Example of using ParseHexToSlice
	hexString := "48656c6c6f2c20576f726c6421"
	hexData := VHtearCryptoutil.ParseHexToSlice(hexString)
	fmt.Printf("Hex Data: %x\n", hexData)

	// Example of using Xor
	dataToXor := []byte("data_to_xor")
	xoredData := VHtearCryptoutil.Xor(dataToXor)
	fmt.Printf("Xored Data: %x\n", xoredData)

	// Example of using CombineBytesToResult
	dataToCombine := []byte{0x12, 0x34}
	result := VHtearCryptoutil.CombineBytesToResult(dataToCombine, 0)
	fmt printf("Combined Result: %x\n", result)

	// Example of using AccessAndTransformElement
	dataToAccess := []byte{0xFF, 0x80}
	element := VHtearCryptoutil.AccessAndTransformElement(dataToAccess, 0)
	fmt.Printf("Accessed and Transformed Element: %x\n", element)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessAndTransformElement

func AccessAndTransformElement(d []byte, i int) byte

func CalculateChecksumAndTransform

func CalculateChecksumAndTransform(key []byte, data []byte) []byte

func CombineBytesToResult

func CombineBytesToResult(d []byte, i int) []byte

func DecryptWithAESGCM

func DecryptWithAESGCM(gcmKey, sign, message, aad []byte) ([]byte, error)

func EncEncKey

func EncEncKey(key *rsa.PublicKey, encryptKey []byte) string

func EncHeaders

func EncHeaders(headers map[string]string) []byte

func EncryptWithAESGCM

func EncryptWithAESGCM(data, gcmKey, nonce, aad []byte) ([]byte, error)

func GenerateAAD

func GenerateAAD(a string, b string, c int, d int, e int, f int) []byte

func GenerateSharedSecret

func GenerateSharedSecret(privateKey, publicKey []byte) ([]byte, error)

func GetIntBytesV2

func GetIntBytesV2(i int) []byte

func GetSHA256Sum

func GetSHA256Sum(args ...interface{}) []byte

func Pad

func Pad(buf []byte, size int) []byte

func Pad256

func Pad256(buf []byte, size int) []byte

func ParseHexToSlice

func ParseHexToSlice(t string) []byte

func Unpad

func Unpad(buf []byte) ([]byte, error)

func Xor

func Xor(buf []byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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