P7S
application/pkcs7-signature
Magic Bytes
Offset: 0
2D 2D 2D 2D 2D 42 45 47 49 4E 20 50 4B 43 53 37
PKCS #7 Signature (P7S) is a standardized digital signature format developed by RSA Laboratories and now maintained by the Internet Engineering Task Force. These files are extensively used in secure email protocols like S/MIME to verify the sender's identity and confirm that the message content remained unaltered during transit. Although P7S files are generally considered safe because they store cryptographic proofs rather than executable logic, ensuring the validity of the underlying certificate is necessary for trust.
Validation Code
How to validate .p7s files in Python
Python
def is_p7s(file_path: str) -> bool:
"""Check if file is a valid P7S by magic bytes."""
signature = bytes([0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x4B, 0x43, 0x53, 0x37])
with open(file_path, "rb") as f:
return f.read(16) == signature
How to validate .p7s files in Node.js
Node.js
function isP7S(buffer: Buffer): boolean {
const signature = Buffer.from([0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x4B, 0x43, 0x53, 0x37]);
return buffer.subarray(0, 16).equals(signature);
}
Go
func IsP7S(data []byte) bool {
signature := []byte{0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x4B, 0x43, 0x53, 0x37}
if len(data) < 16 {
return false
}
return bytes.Equal(data[:16], signature)
}
API Endpoint
GET
/api/v1/p7s
curl https://filesignature.org/api/v1/p7s