crypt

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package crypt opens the encryption of the binary Office formats ([MS-OFFCRYPTO] 2.3): XOR obfuscation, the RC4 encryption of Office 97, and RC4 with a key made by the CryptoAPI. A password is verified against what the file keeps for that before anything is decrypted with it.

These schemes are weak, and are read here because documents kept in them still exist; nothing is written with them.

Index

Constants

View Source
const (
	XOR       = "XOR obfuscation"
	RC4       = "RC4"
	CryptoAPI = "RC4 CryptoAPI"
)

The schemes.

View Source
const DefaultPassword = "VelvetSweatshop"

DefaultPassword is the password Excel encrypts a workbook with when its structure is protected and no password to open it was set ([MS-XLS] 2.2.10).

Variables

View Source
var ErrHeader = errors.New("crypt: the encryption header cannot be read")

ErrHeader is returned for a header of encryption that cannot be read, or that names an algorithm other than RC4.

Functions

This section is empty.

Types

type Header struct {
	Scheme string
	// XOR obfuscation: the key and the verifier made of the password.
	Key, Hash uint16
	// RC4: the salt, and the verifier and its hash, both encrypted.
	Salt, Verifier, VerifierHash []byte
	// KeyBits is the length of a CryptoAPI key.
	KeyBits int
}

Header is what a file keeps of its encryption: the scheme, and what a password is verified against.

func Parse

func Parse(b []byte) (Header, error)

Parse reads the header of an RC4 encryption, which begins with its version: 1.1 for the encryption of Office 97, and 2.2 to 4.2 for the CryptoAPI ([MS-OFFCRYPTO] 2.3.6.1, 2.3.5.1).

func (*Header) Open

func (h *Header) Open(password string, rotate uint) (*Key, bool)

Open makes the key the password gives, and reports whether it is the file's: whether the verifier the file keeps decrypts to what its hash says. For XOR obfuscation rotate is how far the bytes of the key are turned: 2 in a workbook, 7 in a Word document.

type Key

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

Key decrypts what a file encrypted.

func (*Key) Block

func (k *Key) Block(data []byte, block uint32) *rc4.Cipher

Block decrypts in place data that is encrypted on its own with the key of one block, as an object of a presentation is with the key of its number. It returns the cipher, for what follows the data in the same run.

func (*Key) Scheme

func (k *Key) Scheme() string

Scheme names the scheme of the key.

func (*Key) Stream

func (k *Key) Stream(data []byte, blockSize int)

Stream decrypts a stream in place whose blocks of the given size are each encrypted with the key of their number, from the start of the stream: 512 bytes in a Word document, 1024 in a workbook.

func (*Key) XorDocument

func (k *Key) XorDocument(data []byte, at int)

XorDocument decrypts in place a part of a stream of a Word document that is obfuscated, which begins at the given place of the stream. A byte that is zero, or that would become zero, is as it is.

func (*Key) XorWorkbook

func (k *Key) XorWorkbook(body []byte, at int)

XorWorkbook decrypts in place the data of a record of a workbook that is obfuscated ([MS-XLS] 2.2.10): the place in the key is that of the data in the stream, plus the size of the record.

Jump to

Keyboard shortcuts

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