Skip to content

MHT (.mht)

.mht 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

.mht

MIME Type

multipart/related

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .mht files in Python

Python
def is_mht(file_path: str) -> bool:
    """Check if file is a valid MHT 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 .mht files in Node.js

Node.js
function isMHT(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 .mht files in Go

Go
func IsMHT(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/mht
curl https://filesignature.org/api/v1/mht

See the full API documentation for all endpoints and parameters.

Frequently Asked Questions

What is a .mht file?

A .mht file is a MHT file.

What are the magic bytes for .mht files?

The magic bytes for MHT 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 .mht file?

To validate a .mht 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 .mht files?

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

Is it safe to open .mht files?

MHT (.mht) 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.