32 lines
699 B
Plaintext
32 lines
699 B
Plaintext
== How to fix it in pyDes
|
|
|
|
=== Code examples
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
import pyDes
|
|
|
|
cipher = pyDes.des(key) # Noncompliant
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
Since pyDes only provides DES, it is recommended to use another library like pyca.
|
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
|
----
|
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
|
from cryptography.hazmat.backends import default_backend
|
|
|
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../../common/fix/strong-cryptography.adoc[]
|
|
|