ff1

package
v0.0.0-...-6bcf8dd Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ff1 implements the FF1 format-preserving encryption algorithm/scheme https://github.com/capitalone/fpe/blob/master/ff1/ff1.go

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrStringNotInRadix is returned if input or intermediate strings cannot be parsed in the given radix
	ErrStringNotInRadix = errors.New("string is not within base/radix")

	// ErrTweakLengthInvalid is returned if the tweak length is not in the given range
	ErrTweakLengthInvalid = errors.New("tweak must be between 0 and given maxTLen, inclusive")
)

Functions

This section is empty.

Types

type Cipher

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

A Cipher is an instance of the FF1 mode of format preserving encryption using a particular key, radix, and tweak

func NewCipher

func NewCipher(radix int, maxTLen int, key []byte, tweak []byte) (Cipher, error)

NewCipher initializes a new FF1 Cipher for encryption or decryption use based on the radix, max tweak length, key and tweak parameters.

func (Cipher) Decrypt

func (c Cipher) Decrypt(X string) (string, error)

Decrypt decrypts the string X over the current FF1 parameters and returns the plaintext of the same length and format

func (Cipher) DecryptWithTweak

func (c Cipher) DecryptWithTweak(X string, tweak []byte) (string, error)

DecryptWithTweak is the same as Decrypt except it uses the tweak from the parameter rather than the current Cipher's tweak This allows you to re-use a single Cipher (for a given key) and simply override the tweak for each unique data input, which is a practical use-case of FPE for things like credit card numbers.

func (Cipher) Encrypt

func (c Cipher) Encrypt(X string) (string, error)

Encrypt encrypts the string X over the current FF1 parameters and returns the ciphertext of the same length and format

func (Cipher) EncryptWithTweak

func (c Cipher) EncryptWithTweak(X string, tweak []byte) (string, error)

EncryptWithTweak is the same as Encrypt except it uses the tweak from the parameter rather than the current Cipher's tweak This allows you to re-use a single Cipher (for a given key) and simply override the tweak for each unique data input, which is a practical use-case of FPE for things like credit card numbers.

Jump to

Keyboard shortcuts

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