triple_des

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package triple_des implements Triple DES encryption and decryption with streaming support. It provides Triple DES encryption and decryption operations using the standard Triple DES algorithm with support for 16-byte and 24-byte keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStreamDecrypter

func NewStreamDecrypter(r io.Reader, c cipher.TripleDesCipher) io.Reader

NewStreamDecrypter creates a new streaming Triple DES decrypter that reads encrypted data from the provided io.Reader. The decrypter uses the specified cipher interface and validates the key length for proper Triple DES decryption.

func NewStreamEncrypter

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

NewStreamEncrypter creates a new streaming Triple DES encrypter that writes encrypted data to the provided io.Writer. The encrypter uses the specified cipher interface and validates the key length for proper Triple DES encryption.

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 Triple DES 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 // The underlying error that caused the failure
}

EncryptError represents an error when Triple DES encryption operation fails. This error occurs when the encryption process fails due to various reasons. The error includes the underlying error for detailed debugging.

func (EncryptError) Error

func (e EncryptError) Error() string

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

type KeySizeError

type KeySizeError int

KeySizeError represents an error when the Triple DES key size is invalid. Triple DES keys must be exactly 16 or 24 bytes (128 or 192 bits). For 16-byte keys, the implementation automatically expands them to 24 bytes using the pattern key1 + key2 + key1. 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 KeyUnsetError

type KeyUnsetError struct {
}

KeyUnsetError represents an error when the Triple DES key is not set. This error occurs when attempting to perform encryption or decryption operations without first setting a valid key using the SetKey() method.

func (KeyUnsetError) Error

func (k KeyUnsetError) Error() string

Error returns a formatted error message indicating that the key is not set. The message provides guidance to use the SetKey() method to resolve the issue.

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 Triple DES decrypter for standard decryption operations. It implements Triple DES decryption using the standard Triple DES algorithm with support for 16-byte and 24-byte keys and various cipher modes.

func NewStdDecrypter

func NewStdDecrypter(c cipher.TripleDesCipher) *StdDecrypter

NewStdDecrypter creates a new Triple DES decrypter with the specified cipher and key. Validates the key length and initializes the decrypter for Triple DES decryption operations. The key must be 16 or 24 bytes for Triple DES decryption.

func (*StdDecrypter) Decrypt

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

Decrypt decrypts the given byte slice using Triple DES decryption. Creates a Triple DES cipher block and uses the configured cipher interface to perform the decryption operation with proper error handling.

type StdEncrypter

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

StdEncrypter represents a Triple DES encrypter for standard encryption operations. It implements Triple DES encryption using the standard Triple DES algorithm with support for 16-byte and 24-byte keys and various cipher modes.

func NewStdEncrypter

func NewStdEncrypter(c cipher.TripleDesCipher) *StdEncrypter

NewStdEncrypter creates a new Triple DES encrypter with the specified cipher and key. Validates the key length and initializes the encrypter for Triple DES encryption operations. The key must be 16 or 24 bytes for Triple DES encryption.

func (*StdEncrypter) Encrypt

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

Encrypt encrypts the given byte slice using Triple DES encryption. Creates a Triple DES cipher block and uses the configured cipher interface to perform the encryption operation with proper error handling.

type StreamDecrypter

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

StreamDecrypter represents a streaming Triple DES 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 Triple DES decryption. Reads encrypted data from the underlying reader, decrypts it, and fills the provided buffer. Returns the number of bytes read and any error that occurred.

type StreamEncrypter

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

StreamEncrypter represents a streaming Triple DES 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 streaming Triple DES encrypter. Closes the underlying writer if it implements io.Closer.

func (*StreamEncrypter) Write

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

Write implements the io.Writer interface for streaming Triple DES encryption. Encrypts the provided data and writes it to the underlying writer. Returns the number of bytes written and any error that occurred.

Source Files

  • 3des.go
  • errors.go

Jump to

Keyboard shortcuts

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