crypto

package
v0.0.0-...-227fc60 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package crypto provides cryptographic functions for .doc file decryption.

This package implements the RC4 encryption/decryption algorithm used by Microsoft Word documents for password protection and encryption.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateDecryptionKey

func GenerateDecryptionKey(password string, salt []byte) ([]byte, error)

GenerateDecryptionKey creates the decryption key from password and document salt. This follows the MS-DOC specification for password-based encryption.

func GeneratePasswordHash

func GeneratePasswordHash(password string) []byte

GeneratePasswordHash creates a password hash compatible with Word documents. This implements the Word 97-2003 password hashing algorithm.

func VerifyPassword

func VerifyPassword(password string, expectedHash []byte, salt []byte) (bool, error)

VerifyPassword checks if the given password matches the document's password hash.

Types

type EncryptionHeader

type EncryptionHeader struct {
	Version           uint16 // Encryption version
	EncryptionFlags   uint32 // Encryption flags
	HeaderSize        uint32 // Size of encryption header
	ProviderType      uint32 // Cryptographic provider type
	AlgID             uint32 // Algorithm identifier
	AlgHashID         uint32 // Hash algorithm identifier
	KeySize           uint32 // Key size in bits
	ProviderName      string // Cryptographic provider name
	Salt              []byte // Random salt for key derivation
	EncryptedVerifier []byte // Encrypted verifier for password validation
	VerifierHash      []byte // Hash of the verifier
}

EncryptionHeader represents the encryption information stored in the table stream for encrypted Word documents.

func ParseEncryptionHeader

func ParseEncryptionHeader(data []byte) (*EncryptionHeader, error)

ParseEncryptionHeader parses the encryption header from table stream data.

func (*EncryptionHeader) CreateDecryptionCipher

func (h *EncryptionHeader) CreateDecryptionCipher(password string) (*RC4, error)

CreateDecryptionCipher creates an RC4 cipher for decrypting document content.

func (*EncryptionHeader) IsPasswordProtected

func (h *EncryptionHeader) IsPasswordProtected() bool

IsPasswordProtected returns true if the document is password protected.

func (*EncryptionHeader) IsRC4Encryption

func (h *EncryptionHeader) IsRC4Encryption() bool

IsRC4Encryption returns true if the encryption uses RC4 algorithm.

func (*EncryptionHeader) ValidatePassword

func (h *EncryptionHeader) ValidatePassword(password string) (bool, error)

ValidatePassword checks if the provided password is correct for this document.

type RC4

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

RC4 represents an RC4 cipher context.

func NewRC4

func NewRC4(key []byte) (*RC4, error)

NewRC4 creates a new RC4 cipher with the given key.

func (*RC4) Decrypt

func (rc4 *RC4) Decrypt(data []byte) []byte

Decrypt decrypts the given data using RC4. RC4 is symmetric, so this function can also be used for encryption.

Jump to

Keyboard shortcuts

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