Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AES-256 encryption #872

Merged
merged 12 commits into from
Aug 2, 2023
3 changes: 3 additions & 0 deletions .banditrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ skips:
# Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
# => OK, we don't care though
- B101
# B305:blacklist - Use of insecure cipher mode cryptography.hazmat.primitives.ciphers.modes.ECB.
# Need to bypass this check because the PDF specification demands the use of ECB mode on one of the encryption algorithms
andersonhc marked this conversation as resolved.
Show resolved Hide resolved
- B305
7 changes: 5 additions & 2 deletions docs/Encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ If no permission is specified it will default to `all()`.

## Encryption method ##

There are 3 available encryption methods:
There are 4 available encryption methods:

* `NO_ENCRYPTION`
Data is not encrypted, only add the access permission flags.
Expand All @@ -90,7 +90,10 @@ There are 3 available encryption methods:
Default PDF encryption algorithm.

* `AES_128`
Encrypts the data with AES algorithm. Requires the `cryptography` package.
Encrypts the data with 128 bit key AES algorithm. Requires the `cryptography` package.

* `AES_256`
Encrypts the data with 256 bit key AES algorithm. Requires the `cryptography` package.

```python
from fpdf import FPDF
Expand Down
6 changes: 3 additions & 3 deletions fpdf/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def __init__(
self.f_t = Name(field_type) if field_type else None
self.v = value
self.f = sum(flags)
self.contents = PDFString(contents) if contents else None
self.contents = PDFString(contents, encrypt=True) if contents else None
self.a = action
self.dest = dest
self.c = f"[{color[0]} {color[1]} {color[2]}]" if color else None
self.t = PDFString(title) if title else None
self.m = PDFDate(modification_time) if modification_time else None
self.t = PDFString(title, encrypt=True) if title else None
self.m = PDFDate(modification_time, encrypt=True) if modification_time else None
self.quad_points = (
pdf_list(f"{quad_point:.2f}" for quad_point in quad_points)
if quad_points
Expand Down
Loading