crypto

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package crypto provides tools for encrypting and decrypting files using age encryption and Shamir's Secret Sharing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(name string, remove bool) error

Decrypt decrypts a file using age identity obtained through shamir secret sharing.

Example
package main

import (
	"log"
	"os"

	"gitlab.com/fav-cli/fav/pkg/crypto"
)

func main() {
	tmpFile, err := os.CreateTemp("/tmp", "fav-test-file")
	if err != nil {
		log.Fatal(err)
	}
	defer tmpFile.Close()

	_, err = tmpFile.WriteString("test data")
	if err != nil {
		log.Fatal(err)
	}

	err = crypto.Encrypt(tmpFile.Name())
	if err != nil {
		log.Fatal(err)
	}

	err = crypto.Decrypt(tmpFile.Name(), false)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func Encrypt

func Encrypt(name string) error

Encrypt encrypts the specified file using age encryption and distributes the resulting identity using Shamir's Secret Sharing.

Example
package main

import (
	"log"
	"os"

	"gitlab.com/fav-cli/fav/pkg/crypto"
)

func main() {
	tmpFile, err := os.CreateTemp("/tmp", "fav-test-file")
	if err != nil {
		log.Fatal(err)
	}
	defer tmpFile.Close()

	_, err = tmpFile.WriteString("test data")
	if err != nil {
		log.Fatal(err)
	}

	err = crypto.Encrypt(tmpFile.Name())
	if err != nil {
		log.Fatal(err)
	}
}
Output:

Types

type SharedSecret

type SharedSecret struct {
	FileName string
	Data     []byte
}

SharedSecret contains information about a shared secret.

type SharedSecrets

type SharedSecrets struct {
	Data []SharedSecret
}

SharedSecrets represents a collection of shared secrets.

Jump to

Keyboard shortcuts

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