crypto

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 18 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcChecksums added in v1.7.3

func CalcChecksums(reader io.Reader, checksumType ...Algorithm) (map[Algorithm]string, error)

CalcChecksums calculates all hashes at once using AsyncMultiWriter. The file is therefore read only once.

func CalcChecksumsBytes added in v1.7.3

func CalcChecksumsBytes(reader io.Reader, checksumType ...Algorithm) (map[Algorithm][]byte, error)

CalcChecksumsBytes calculates hashes like `CalcChecksums`, returns result as bytes

func Decrypt

func Decrypt(formattedCipherText, key, keyId string) (string, error)

func Encrypt

func Encrypt(text, key, keyId string) (string, error)

format encrypted text , keyId is first 6 chars of hashed(sha256) signing key {{key-id}}${{algo}}${{encrypted-value}} example: e67gef$aes256$adsad321424324fdsdfs3Rddi90oP34xV

func GenerateKeyId

func GenerateKeyId(key string) (string, error)

keyId is first 6 chars of hashed(sha256) signing key

func GenerateRandomKeyString

func GenerateRandomKeyString(keySize int) (string, error)

func GetFileChecksums added in v1.7.3

func GetFileChecksums(filePath string, checksumType ...Algorithm) (checksums map[Algorithm]string, err error)

func IsTextEncrypted

func IsTextEncrypted(formattedCipherText, key, keyId string) (bool, error)

Types

type Algorithm added in v1.7.3

type Algorithm int
const (
	MD5 Algorithm = iota
	SHA1
	SHA256
)

type Checksum added in v1.7.3

type Checksum struct {
	Sha1   string `json:"sha1,omitempty"`
	Md5    string `json:"md5,omitempty"`
	Sha256 string `json:"sha256,omitempty"`
}

func CalcChecksumDetails added in v1.7.3

func CalcChecksumDetails(filePath string) (checksum Checksum, err error)

func (*Checksum) IsEmpty added in v1.7.3

func (c *Checksum) IsEmpty() bool

func (*Checksum) IsEqual added in v1.7.3

func (c *Checksum) IsEqual(other Checksum) (bool, error)

If the 'other' checksum matches the current one, return true. 'other' checksum may contain regex values for sha1, sha256 and md5.

type FileDetails added in v1.7.3

type FileDetails struct {
	Checksum Checksum
	Size     int64
}

func GetFileDetails added in v1.7.3

func GetFileDetails(filePath string, includeChecksums bool) (details *FileDetails, err error)

Jump to

Keyboard shortcuts

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