xiphr

package module
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 8 Imported by: 0

README

Xiphr

Go Reference Go Report Card Test Status Release Status License

Xiphr is a curated collection of cryptographic primitives put together to perform password-based asymmetric encryption. It is written in Go and can be used as a library or a CLI tool.

Features
  • Password based public key generation.
  • Encrypt data with public key generated from a password.
  • Encrypt data with password or a generated private key.
  • Decrypt data with password or a a given private key (works on all combinations of encryption).
  • Supports stream cipher along with stream compression thereby keeping a low memory footprint. Makes it handy for encrypting large files or data streams.
Under the hood

Xiphr uses the following cryptographic primitives and libraries to encrypt/decrypt and compress/decompress data:

Install or Update
go get -u dev.shib.me/xiphr
Usage Example
package main

import (
	"encoding/base32"
	"fmt"

	"dev.shib.me/xiphr"
)

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

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

	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))
}

The output of the above code looks something like this:

PublicKey: MS5JUG7ZVJLETJA7WE2XKFHRE4PP6LKYCTEF2FTNUJ5QEZJIGZPCAIABX7UMDM7DPZX6WNOXICBUBBPPKE
Encrypted: AQQCAAN75DA3HY36N7VTLV2AQNAIL32RBWA2GJY7JNFA7QNOBT4CFXFBZMKY36DGE6FBKPATB7EJTD5SCNXI6URGO4WERYXYHYTL4RCXLRMYBG4K4UDZ5HGE7APXUVZ4RNESUV3EWVDJBHUAT5F7U5BFNUMTXB72Q3AZBGZDN3KXBWLUX23Q
Decrypted: Hello World!
Basic CLI

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

You can also install with brew using the following command

brew install shibme/beta/xiphr

Alternatively try it out using docker

docker run --rm -v $(pwd):/data/ -it shibme/xiphr help

Documentation

Index

Constants

View Source
const (

	// PrivateKeyLength is the length of a private key.
	PrivateKeyLength = cipherKeyLength
	// PublicKeyLength is the length of a public key.
	PublicKeyLength = cipherKeyLength + kdfSpecLength
	// CipherTextMinLength is the minimum length of a ciphertext.
	CipherTextMinLength = symcipher.CipherTextMinLength
)

Variables

View Source
var (
	Version = "dev"
)

Functions

This section is empty.

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 32 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() (*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 51 bytes long.

func (*PublicKey) Bytes

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

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
ecc

Jump to

Keyboard shortcuts

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