Esempio n. 1
0
 def encrypt(self, prev, password, rc):
     encrypt = prev.trailer["/Encrypt"].getObject()
     if encrypt["/V"] == 2:
         rev = 3
         keylen = 128 // 8
     else:
         rev = 2
         keylen = 40 // 8
     P = encrypt["/P"].getObject()
     O = encrypt["/O"].getObject()
     ID_1 = prev.trailer["/ID"].getObject()[0]
     real_U = encrypt["/U"].getObject().original_bytes
     if rev == 2:
         U, key = pdf._alg34(password, O, P, ID_1)
     else:
         assert rev == 3
         U, key = pdf._alg35(
             password,
             rev,
             keylen,
             O,
             P,
             ID_1,
             encrypt.get("/EncryptMetadata",
                         pdf.BooleanObject(False)).getObject(),
         )
         U, real_U = U[:16], real_U[:16]
     assert U == real_U
     self._encrypt_key = key
Esempio n. 2
0
 def encrypt(self, prev, password, rc):
     encrypt = prev.trailer["/Encrypt"].getObject()
     if encrypt["/V"] == 2:
         rev = 3
         keylen = int(128 / 8)
     else:
         rev = 2
         keylen = int(40 / 8)
     P = encrypt["/P"]
     O = encrypt["/O"]
     ID_1 = prev.trailer["/ID"][0]
     if rev == 2:
         U, key = pdf._alg34(password, O, P, ID_1)
     else:
         assert rev == 3
         U, key = pdf._alg35(password, rev, keylen, O, P, ID_1, False)
     self._encrypt_key = key