crypto

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 11 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt added in v0.5.0

func AESCBCDecrypt(key, iv, ciphertext []byte) ([]byte, error)

AESCBCDecrypt decrypts data using AES-CBC mode with PKCS5 unpadding. Supports all AES key sizes: 16 bytes (AES-128), 24 bytes (AES-192), or 32 bytes (AES-256).

func AESCBCEncrypt added in v0.5.0

func AESCBCEncrypt(key, iv, plaintext []byte) ([]byte, error)

AESCBCEncrypt encrypts data using AES-CBC mode with PKCS5 padding. Supports all AES key sizes: 16 bytes (AES-128), 24 bytes (AES-192), or 32 bytes (AES-256).

func AESGCMDecrypt added in v0.4.6

func AESGCMDecrypt(key, nonce, ciphertext []byte) ([]byte, error)

AESGCMDecrypt decrypts data using AES-GCM mode.

func AESGCMDecryptBlob added in v0.5.0

func AESGCMDecryptBlob(key, blob, aad []byte) ([]byte, error)

AESGCMDecryptBlob decrypts a blob shaped as [12B nonce][ciphertext+16B GCM tag] with caller-supplied AAD. Used by protocols that wrap AES-GCM output with a fixed-length nonce prefix (Yandex passwords/cards).

func AESGCMEncrypt added in v0.4.6

func AESGCMEncrypt(key, nonce, plaintext []byte) ([]byte, error)

AESGCMEncrypt encrypts data using AES-GCM mode.

func DES3Decrypt added in v0.4.6

func DES3Decrypt(key, iv, ciphertext []byte) ([]byte, error)

DES3Decrypt decrypts data using 3DES-CBC mode with PKCS5 unpadding.

func DES3Encrypt added in v0.4.6

func DES3Encrypt(key, iv, plaintext []byte) ([]byte, error)

DES3Encrypt encrypts data using 3DES-CBC mode with PKCS5 padding.

func DecryptChromiumCBC added in v1.1.0

func DecryptChromiumCBC(key, ciphertext []byte) ([]byte, error)

DecryptChromiumCBC decrypts a prefixed AES-CBC blob (version(3B)+ct) with Chromium's fixed IV, retrying with kEmptyKey to recover crbug.com/40055416 KWallet-corrupted data. Used by macOS/Linux v10 and Linux v11 (both AES-128).

func DecryptChromiumGCM added in v1.1.0

func DecryptChromiumGCM(key, ciphertext []byte) ([]byte, error)

DecryptChromiumGCM decrypts a prefixed AES-GCM blob: version(3B)+nonce(12B)+ct+tag. Used by Windows v10 (AES-256) and v20; the layout is identical and platform-neutral.

func DecryptDPAPI added in v0.5.0

func DecryptDPAPI(_ []byte) ([]byte, error)

func DecryptYandexIntermediateKey added in v0.5.0

func DecryptYandexIntermediateKey(masterKey, blob []byte) ([]byte, error)

DecryptYandexIntermediateKey unwraps the per-DB data key from meta.local_encryptor_data.

func PBKDF2Key added in v0.4.6

func PBKDF2Key(password, salt []byte, iterations, keyLen int, h func() hash.Hash) []byte

PBKDF2Key derives a key from the password, salt and iteration count, returning a []byte of length keylen that can be used as cryptographic key. The key is derived based on the method described as PBKDF2 with the HMAC variant using the supplied hash function.

For example, to use a HMAC-SHA-1 based PBKDF2 key derivation function, you can get a derived key for e.g. AES-256 (which needs a 32-byte key) by doing:

dk := PBKDF2Key([]byte("some password"), salt, 4096, 32, sha1.New)

Remember to get a good random salt. At least 8 bytes is recommended by the RFC.

Using a higher iteration count will increase the cost of an exhaustive search but will also make derivation proportionally slower. Copy from https://golang.org/x/crypto/pbkdf2

Types

type ASN1PBE

type ASN1PBE interface {
	Decrypt(key []byte) ([]byte, error)
	Encrypt(key, plaintext []byte) ([]byte, error)
}

ASN1PBE represents a Password-Based Encryption structure from Firefox's NSS. The key parameter semantics vary by implementation:

  • privateKeyPBE / passwordCheckPBE: key is the global salt used for key derivation
  • credentialPBE: key is the already-derived master key

func NewASN1PBE

func NewASN1PBE(b []byte) (pbe ASN1PBE, err error)

type CipherVersion added in v0.5.0

type CipherVersion string

CipherVersion represents the encryption version used by Chromium browsers.

const (
	// CipherV10 is Chrome 80+ encryption (AES-GCM on Windows, AES-CBC on macOS/Linux).
	CipherV10 CipherVersion = "v10"

	// CipherV11 is the Linux-only AES-CBC variant where the key comes from
	// libsecret / kwallet. Same algorithm as CipherV10; only the key source differs.
	CipherV11 CipherVersion = "v11"

	// CipherV20 is Chrome 127+ App-Bound Encryption.
	CipherV20 CipherVersion = "v20"

	// CipherV12 is Chromium's SecretPortalKeyProvider (Flatpak / xdg-desktop-portal) tier —
	// HKDF-SHA256 + AES-256-GCM with a secret retrieved via org.freedesktop.portal.Desktop.
	// Recognized by DetectVersion so decryptValue can emit a known-gap error rather than a
	// generic "unsupported cipher version" message; not yet implemented.
	CipherV12 CipherVersion = "v12"

	// CipherDPAPI is pre-Chrome 80 raw DPAPI encryption (no version prefix).
	CipherDPAPI CipherVersion = "dpapi"
)

func DetectVersion added in v0.5.0

func DetectVersion(ciphertext []byte) CipherVersion

DetectVersion identifies the encryption version from a ciphertext prefix.

Directories

Path Synopsis
windows

Jump to

Keyboard shortcuts

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