How to check if an ePub file is DRM-protected?

Mark Vincze picture Mark Vincze · Jan 21, 2013 · Viewed 12.5k times · Source

Is there any programmatic way to safely check whether if an epub file is DRM-protected (encrypted)?

I have found that there might be a rights.xml and an encryption.xml in the META-INF directory. Does the existance of any or both of these files mean that the content is encrypted and if not, is there any other way to check?
(To be clear, I do not want to read ePubs with DRM at all, I just want to check whether they are encrypted or not.)

Answer

user663031 picture user663031 · Jan 22, 2013

FWIW the Wikipedia epub article states

When present, DRMed EPUB files must contain a file called rights.xml within the META-INF directory at the root level of the ZIP container.

epubcheck as of v1.0 is reported to detect DRM-protection via the existence of encryption.xml and report an error. The epub3 spec says

An optional encryption.xml file within the META-INF directory at the root level of the container file system holds all encryption information on the contents of the container. This file is an XML document whose root element is encryption. The encryption element contains child elements of type EncryptedKey and EncryptedData as defined by [XML ENC Core]. Each EncryptedData element describes how one or more files within the container are encrypted. Consequently, if any resource within the container is encrypted, encryption.xml must be present to indicate that the resource is encrypted and provide information on how it is encrypted.

The EPUB3 is vague on rights.xml, its meaning and whether it is mandatory for DRM'd files, so it might be best not to depend on it.