xipher

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 11 Imported by: 0

README

Xipher

Go Reference Go Report Card Test Status Release Status License

Xipher is a curated collection of cryptographic primitives put together to key/password based asymmetric encryption.

What does it do?
  • Encrypts data with the public key generated based on a password.
  • Supports stream cipher along with stream compression, resulting in lower memory footprint.
  • Supports post-quantum cryptography using the Kyber algorithm.

Demo

Demo

CLI Installation

Download the latest binary from the releases page and add it to your path.

Homebrew

Xipher can be installed with brew using the following command on macOS

brew install shibme/tap/xipher
Install Script
Install Latest Version

With Shell (MacOs/Linux):

curl -fsSL https://dev.shib.me/xipher/install.sh | sh

With PowerShell (Windows):

irm https://dev.shib.me/xipher/install.ps1 | iex
Install Specific Version

With Shell (MacOs/Linux):

curl -fsSL https://dev.shib.me/xipher/install.sh | sh -s v0.9.2

With PowerShell (Windows):

$v="0.9.2"; irm https://dev.shib.me/xipher/install.ps1 | iex
Docker

You can also run Xipher without installing using Docker:

docker run --rm -v $PWD:/data -it shibme/xipher help

Using as a Go package

Install the package

go get -u dev.shib.me/xipher

Use it in your code

package main

import (
	"encoding/base32"
	"fmt"

	"dev.shib.me/xipher"
)

func main() {
	// Creating a new private key for password
	privKey, err := xipher.NewPrivateKeyForPassword([]byte("Paws0meKittyKuwan!"))
	if err != nil {
		panic(err)
	}

	// Deriving  public key from private key
	pubKey, err := privKey.PublicKey(false)
	if err != nil {
		panic(err)
	}
	publicKeyBytes, err := pubKey.Bytes()
	if err != nil {
		panic(err)
	}
	fmt.Println("PublicKey:", base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(publicKeyBytes))

	platinText := []byte("Hello World!")

	// Encrypting plain text with public key
	cipherText, err := pubKey.Encrypt(platinText, true)
	if err != nil {
		panic(err)
	}
	fmt.Println("Encrypted:", base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(cipherText))

	// Decrypting cipher text with private key
	plainText, err := privKey.Decrypt(cipherText)
	if err != nil {
		panic(err)
	}
	fmt.Println("Decrypted:", string(plainText))
}

Under the hood

Xipher uses the following algorithms and libraries to achieve its functionality:

Disclaimer

This tool/library is provided without any warranties, and there is no guarantee of its stability. Due to the experimental nature of some of its components, it is anticipated that modifications to the code, repository, and API will be made in the future. Caution is advised before incorporating this into a production application. Please report any identified security issues promptly. Your cooperation in notifying us of such concerns is highly appreciated.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VersionInfo added in v1.1.0

func VersionInfo() string

Types

type PrivateKey

type PrivateKey struct {
	// contains filtered or unexported fields
}

func NewPrivateKey

func NewPrivateKey() (*PrivateKey, error)

NewPrivateKey creates a new random private key.

func NewPrivateKeyForPassword

func NewPrivateKeyForPassword(password []byte) (*PrivateKey, error)

NewPrivateKeyForPassword creates a new private key for the given password.

func NewPrivateKeyForPasswordAndSpec

func NewPrivateKeyForPasswordAndSpec(password []byte, iterations, memory, threads uint8) (*PrivateKey, error)

NewPrivateKeyForPasswordAndSpec creates a new private key for the given password and kdf spec.

func ParsePrivateKey

func ParsePrivateKey(key []byte) (*PrivateKey, error)

ParsePrivateKey parses the given bytes and returns a corresponding private key. the given bytes must be 33 bytes long.

func (*PrivateKey) Bytes

func (privateKey *PrivateKey) Bytes() ([]byte, error)

Bytes returns the private key as bytes only if it is not password based.

func (*PrivateKey) Decrypt

func (privateKey *PrivateKey) Decrypt(ciphertext []byte) (data []byte, err error)

Decrypt decrypts the given ciphertext and returns the decrypted data.

func (*PrivateKey) DecryptStream

func (privateKey *PrivateKey) DecryptStream(dst io.Writer, src io.Reader) (err error)

DecryptStream decrypts src and writes to dst.

func (*PrivateKey) Encrypt

func (privateKey *PrivateKey) Encrypt(data []byte, compression bool) (ciphertext []byte, err error)

Encrypt encrypts data with the private key treating it as a symmetric key.

func (*PrivateKey) EncryptStream

func (privateKey *PrivateKey) EncryptStream(dst io.Writer, src io.Reader, compression bool) (err error)

EncryptStream encrypts src with the private key treating it as a symmetric key and writes to dst.

func (*PrivateKey) NewDecryptingReader

func (privateKey *PrivateKey) NewDecryptingReader(src io.Reader) (io.ReadCloser, error)

func (*PrivateKey) NewEncryptingWriter

func (privateKey *PrivateKey) NewEncryptingWriter(dst io.Writer, compression bool) (writer io.WriteCloser, err error)

func (*PrivateKey) PublicKey

func (privateKey *PrivateKey) PublicKey(pq bool) (*PublicKey, error)

PublicKey returns the public key corresponding to the private key.

type PublicKey

type PublicKey struct {
	// contains filtered or unexported fields
}

func ParsePublicKey

func ParsePublicKey(pubKeyBytes []byte) (*PublicKey, error)

ParsePublicKey parses the given bytes and returns a corresponding public key. the given bytes must be at least 33 bytes long.

func (*PublicKey) Bytes

func (publicKey *PublicKey) Bytes() ([]byte, error)

Bytes returns the public key as bytes.

func (*PublicKey) Encrypt

func (publicKey *PublicKey) Encrypt(data []byte, compression bool) (ciphertext []byte, err error)

Encrypt encrypts data with the public key.

func (*PublicKey) EncryptStream

func (publicKey *PublicKey) EncryptStream(dst io.Writer, src io.Reader, compression bool) (err error)

EncryptStream encrypts src with the public key and writes to dst.

func (*PublicKey) NewEncryptingWriter

func (publicKey *PublicKey) NewEncryptingWriter(dst io.Writer, compression bool) (writer io.WriteCloser, err error)

Directories

Path Synopsis
cli
internal
asx
ecc
kyb
xcp

Jump to

Keyboard shortcuts

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