crypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package crypto contains encryption-decryption helper functions.

Index

Constants

This section is empty.

Variables

View Source
var ErrShortCiphertext = errors.New("input too short to be valid ciphertext")

ErrShortCiphertext is an error that has text too short.

Functions

func NewCryptoReader

func NewCryptoReader(bm cipher.BlockMode, source io.ReadCloser) io.ReadCloser

func NewCryptoWriter

func NewCryptoWriter(bm cipher.BlockMode, sink io.WriteCloser) io.WriteCloser

NewCryptoWriter returns block cipher writer. from https://github.com/acasajus/dkeyczar/blob/master/streams.go

func Pkcs5pad

func Pkcs5pad(data []byte, blocksize int) []byte

Pkcs5pad is a padding function that uses the PKCS5 method.

func Pkcs5unpad

func Pkcs5unpad(data []byte) []byte

Pkcs5unpad is a stripping function that reverts the PKCS5 method.

Types

type SecretBox

type SecretBox interface {
	// NewEncryptReader returns EncryptReader from given io.Reader.
	NewEncryptReader(io.Reader) (io.Reader, error)
	// NewDecryptReader returns DecryptReader from given io.Reader.
	NewDecryptReader(src io.Reader) (io.Reader, error)
	// NewEncryptWriter returns EncryptWriter from given io.Writer.
	NewEncryptWriter(dst io.Writer) (io.WriteCloser, error)
	// NewDecryptWriter returns DecryptWriter from given io.Writer.
	NewDecryptWriter(dst io.Writer) (io.WriteCloser, error)
	// EncryptedSize returns encrypted data size from given raw data size.
	EncryptedSize(size uint64) (uint64, error)
	// DecryptedSize returns decrypted data size from given raw data size.
	DecryptedSize(size uint64) (uint64, error)
}

SecretBox is an encryption and decryption provider.

func NewSecretBox

func NewSecretBox(key []byte) SecretBox

NewSecretBox returns a SecretBox object with a provided key.

Here is the validation code written for Python:

import os,binascii
key=binascii.b2a_base64(os.urandom(32),newline=False)
print(key.decode('us-ascii'))

Jump to

Keyboard shortcuts

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