Skip to content

checksum.py

ofrak.core.checksum

Md5Analyzer (Analyzer)

Calculates the MD5 (Message Digest 5) cryptographic hash of binary data, producing a 128-bit fingerprint. Use for file identification by comparing against known MD5 databases, quick integrity verification to detect modifications, tracking changes during binary modification workflows, or creating file catalogs.

analyze(self, resource, config=None) async

Analyze a resource for to extract specific ResourceAttributes.

Users should not call this method directly; rather, they should run Resource.run or Resource.analyze.

Parameters:

Name Type Description Default
resource Resource

The resource that is being analyzed

required
config

Optional config for analyzing. If an implementation provides a default, this default will always be used when config would otherwise be None. Note that a copy of the default config will be passed, so the default config values cannot be modified persistently by a component run.

None

Returns:

Type Description
Md5Attributes

The analysis results

Source code in ofrak/core/checksum.py
async def analyze(self, resource: Resource, config=None) -> Md5Attributes:
    data = await resource.get_data()
    md5 = hashlib.md5()
    md5.update(data)
    return Md5Attributes(md5.hexdigest())

Md5Attributes (ResourceAttributes) dataclass

Md5Attributes(checksum: str)

Sha256Analyzer (Analyzer)

Calculates the SHA-256 (Secure Hash Algorithm 256-bit) cryptographic hash of binary data, producing a 256-bit fingerprint. Use for file identification with high security, integrity verification for security-critical applications, malware analysis and sample tracking, creating file signatures for threat intelligence, or compliance scenarios requiring secure hashing.

analyze(self, resource, config=None) async

Analyze a resource for to extract specific ResourceAttributes.

Users should not call this method directly; rather, they should run Resource.run or Resource.analyze.

Parameters:

Name Type Description Default
resource Resource

The resource that is being analyzed

required
config

Optional config for analyzing. If an implementation provides a default, this default will always be used when config would otherwise be None. Note that a copy of the default config will be passed, so the default config values cannot be modified persistently by a component run.

None

Returns:

Type Description
Sha256Attributes

The analysis results

Source code in ofrak/core/checksum.py
async def analyze(self, resource: Resource, config=None) -> Sha256Attributes:
    data = await resource.get_data()
    sha256 = hashlib.sha256()
    sha256.update(data)
    return Sha256Attributes(sha256.hexdigest())

Sha256Attributes (ResourceAttributes) dataclass

Sha256Attributes(checksum: str)