2023-06-20 10:27:53 +02:00
|
|
|
== How to fix it in pyDes
|
|
|
|
|
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
2023-08-21 15:22:49 +02:00
|
|
|
[source,python,diff-id=31,diff-type=noncompliant]
|
2023-06-20 10:27:53 +02:00
|
|
|
----
|
|
|
|
import pyDes
|
|
|
|
|
2023-08-21 15:22:49 +02:00
|
|
|
pyDes.des(key) # Noncompliant
|
2023-06-20 10:27:53 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
Since pyDes only provides DES, it is recommended to use another library like pyca.
|
|
|
|
|
2023-08-21 15:22:49 +02:00
|
|
|
[source,python,diff-id=31,diff-type=compliant]
|
2023-06-20 10:27:53 +02:00
|
|
|
----
|
|
|
|
from cryptography.hazmat.primitives.ciphers import (
|
2023-08-21 15:22:49 +02:00
|
|
|
Cipher,
|
|
|
|
algorithms,
|
2023-06-20 10:27:53 +02:00
|
|
|
modes,
|
|
|
|
)
|
|
|
|
from cryptography.hazmat.backends import default_backend
|
|
|
|
|
|
|
|
Cipher(algorithms.AES(key), modes.GCM(iv), backend=default_backend())
|
|
|
|
----
|
|
|
|
|
|
|
|
=== How does this work?
|
|
|
|
|
|
|
|
include::../../common/fix/fix.adoc[]
|