Skip to content

MHTML (.mhtml)

.mhtml file signature | multipart/related

Safe

Magic Bytes

Offset 0
4D 49 4D 45 2D 56 65 72 73 69 6F 6E 3A 20 31 2E 30

Sources: Apache Tika

Extension

.mhtml

MIME Type

multipart/related

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .mhtml files in Python

Python
def is_mhtml(file_path: str) -> bool:
    """Check if file is a valid MHTML by magic bytes."""
    signature = bytes([0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E, 0x30])
    with open(file_path, "rb") as f:
        return f.read(17) == signature

How to validate .mhtml files in Node.js

Node.js
function isMHTML(buffer: Buffer): boolean {
  const signature = Buffer.from([0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E, 0x30]);
  return buffer.subarray(0, 17).equals(signature);
}

How to validate .mhtml files in Go

Go
func IsMHTML(data []byte) bool {
    signature := []byte{0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E, 0x30}
    if len(data) < 17 {
        return false
    }
    return bytes.Equal(data[:17], signature)
}

API Endpoint

GET /api/v1/mhtml
curl https://filesignature.org/api/v1/mhtml

See the full API documentation for all endpoints and parameters.

Frequently Asked Questions

What is a .mhtml file?

A .mhtml file is a MHTML file.

What are the magic bytes for .mhtml files?

The magic bytes for MHTML files are 4D 49 4D 45 2D 56 65 72 73 69 6F 6E 3A 20 31 2E 30 at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .mhtml file?

To validate a .mhtml file, read the first bytes of the file and compare them against the known magic bytes (4D 49 4D 45 2D 56 65 72 73 69 6F 6E 3A 20 31 2E 30) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .mhtml files?

The primary MIME type for .mhtml files is multipart/related.

Is it safe to open .mhtml files?

MHTML (.mhtml) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.