blowfish

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package blowfish implements Blowfish encryption and decryption with streaming support. It provides Blowfish encryption and decryption operations using the standard Blowfish algorithm with support for variable key sizes from 32 to 448 bits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStreamDecrypter

func NewStreamDecrypter(r io.Reader, c *cipher.BlowfishCipher) io.Reader

NewStreamDecrypter creates a new streaming Blowfish decrypter that reads encrypted data from the provided io.Reader. The decrypter uses the specified cipher interface and validates the key length and cipher mode for proper Blowfish decryption. Only CBC, CTR, ECB, CFB, and OFB modes are supported.

func NewStreamEncrypter

func NewStreamEncrypter(w io.Writer, c *cipher.BlowfishCipher) io.WriteCloser

NewStreamEncrypter creates a new streaming Blowfish encrypter that writes encrypted data to the provided io.Writer. The encrypter uses the specified cipher interface and validates the key length and cipher mode for proper Blowfish encryption. Only CBC, CTR, ECB, CFB, and OFB modes are supported.

Types

type BufferError

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

BufferError represents an error when the buffer size is too small. This error occurs when the provided buffer is too small to hold the decrypted data. The error includes both buffer size and data size for detailed debugging.

func (BufferError) Error

func (e BufferError) Error() string

Error returns a formatted error message describing the buffer size issue. The message includes both buffer size and data size for debugging.

type DecryptError

type DecryptError struct {
	Err error // The underlying error that caused the failure
}

DecryptError represents an error when Blowfish decryption operation fails. This error occurs when the decryption process fails due to various reasons. The error includes the underlying error for detailed debugging.

func (DecryptError) Error

func (e DecryptError) Error() string

Error returns a formatted error message describing the decryption failure. The message includes the underlying error for debugging.

type EncryptError

type EncryptError struct {
	Err error
}

EncryptError represents an error when Blowfish encryption operation fails. This error occurs when the encryption process fails due to various reasons.

func (EncryptError) Error

func (e EncryptError) Error() string

type KeySizeError

type KeySizeError int

KeySizeError represents an error when the Blowfish key size is invalid. Blowfish keys must be between 1 and 56 bytes. This error occurs when the provided key does not meet these size requirements.

func (KeySizeError) Error

func (k KeySizeError) Error() string

Error returns a formatted error message describing the invalid key size. The message includes the actual key size and the required sizes for debugging.

type ReadError

type ReadError struct {
	Err error // The underlying error that caused the failure
}

ReadError represents an error when reading encrypted data fails. This error occurs when reading encrypted data from the underlying reader fails. The error includes the underlying error for detailed debugging.

func (ReadError) Error

func (e ReadError) Error() string

Error returns a formatted error message describing the read failure. The message includes the underlying error for debugging.

type StdDecrypter

type StdDecrypter struct {
	Error error // Error field for storing decryption errors
	// contains filtered or unexported fields
}

StdDecrypter represents a Blowfish decrypter for standard decryption operations. It implements Blowfish decryption using the standard Blowfish algorithm with support for different key sizes and various cipher modes.

func NewStdDecrypter

func NewStdDecrypter(c *cipher.BlowfishCipher) *StdDecrypter

NewStdDecrypter creates a new Blowfish decrypter with the specified cipher and key. Validates the key length and cipher mode, then initializes the decrypter for Blowfish decryption operations. The key must be between 32 and 448 bits (4 to 56 bytes). Only CBC, CTR, ECB, CFB, and OFB modes are supported.

func (*StdDecrypter) Decrypt

func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)

Decrypt decrypts the given byte slice using Blowfish decryption. Creates a Blowfish cipher block and uses the configured cipher interface to perform the decryption operation with proper error handling. Returns empty data when input is empty.

type StdEncrypter

type StdEncrypter struct {
	Error error // Error field for storing encryption errors
	// contains filtered or unexported fields
}

StdEncrypter represents a Blowfish encrypter for standard encryption operations. It implements Blowfish encryption using the standard Blowfish algorithm with support for different key sizes and various cipher modes.

func NewStdEncrypter

func NewStdEncrypter(c *cipher.BlowfishCipher) *StdEncrypter

NewStdEncrypter creates a new Blowfish encrypter with the specified cipher and key. Validates the key length and cipher mode, then initializes the encrypter for Blowfish encryption operations. The key must be between 32 and 448 bits (4 to 56 bytes). Only CBC, CTR, ECB, CFB, and OFB modes are supported.

func (*StdEncrypter) Encrypt

func (e *StdEncrypter) Encrypt(src []byte) (dst []byte, err error)

Encrypt encrypts the given byte slice using Blowfish encryption. Creates a Blowfish cipher block and uses the configured cipher interface to perform the encryption operation with proper error handling. Returns empty data when input is empty.

type StreamDecrypter

type StreamDecrypter struct {
	Error error // Error field for storing decryption errors
	// contains filtered or unexported fields
}

StreamDecrypter represents a streaming Blowfish decrypter that implements io.Reader. It provides efficient decryption for large data streams by processing data in chunks and reading decrypted output from the underlying reader.

func (*StreamDecrypter) Read

func (d *StreamDecrypter) Read(p []byte) (n int, err error)

Read implements the io.Reader interface for streaming Blowfish decryption. On the first call, reads all encrypted data from the underlying reader and decrypts it. Subsequent calls return chunks of the decrypted data to maintain streaming interface.

type StreamEncrypter

type StreamEncrypter struct {
	Error error // Error field for storing encryption errors
	// contains filtered or unexported fields
}

StreamEncrypter represents a streaming Blowfish encrypter that implements io.WriteCloser. It provides efficient encryption for large data streams by processing data in chunks and writing encrypted output to the underlying writer.

func (*StreamEncrypter) Close

func (e *StreamEncrypter) Close() error

Close implements the io.Closer interface for the Blowfish stream encrypter. Closes the underlying writer if it implements io.Closer. Note: All data is processed in Write method for compatibility with cipher interface.

func (*StreamEncrypter) Write

func (e *StreamEncrypter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for streaming Blowfish encryption. Provides improved performance through cipher block reuse while maintaining compatibility. Accumulates data and processes it using the cipher interface for consistency.

type UnsupportedBlockModeError added in v1.1.7

type UnsupportedBlockModeError struct {
	Mode string // The unsupported mode name
}

UnsupportedBlockModeError represents an error when an unsupported block mode is used.

func (UnsupportedBlockModeError) Error added in v1.1.7

Error returns a formatted error message describing the unsupported mode. The message includes the mode name and explains why it's not supported.

Source Files

  • blowfish.go
  • errors.go

Jump to

Keyboard shortcuts

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