32 lines
715 B
Plaintext
Raw Normal View History

2023-06-12 15:58:19 +02:00
== How to fix it in PyCrypto
=== Code examples
include::../../common/fix/code-rationale.adoc[]
==== Noncompliant code example
[source,python,diff-id=1,diff-type=noncompliant]
----
from Crypto.Cipher import DES
cipher = DES.new(key) # Noncompliant
----
==== Compliant solution
PyCrypto is deprecated, thus 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[]