
* Modify rule S3329: Correct example code * Aligned compliant and noncompliant code * Use AES/CBC/PKCS5Padding in all examples for Java and Kotlin
47 lines
783 B
Plaintext
47 lines
783 B
Plaintext
== How to fix it in pyca
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
from cryptography.hazmat.primitives.ciphers import (
|
|
Cipher,
|
|
algorithms,
|
|
modes,
|
|
)
|
|
|
|
iv = b"exampleIV1234567"
|
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
|
|
|
cipher.encryptor() # Noncompliant
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
:explicit_strong: os.urandom
|
|
|
|
include::../../common/fix/explicit-fix.adoc[]
|
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
|
----
|
|
from os import urandom
|
|
|
|
from cryptography.hazmat.primitives.ciphers import (
|
|
Cipher,
|
|
algorithms,
|
|
modes,
|
|
)
|
|
|
|
iv = urandom(16)
|
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
|
|
|
cipher.encryptor()
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../../common/fix/fix.adoc[]
|
|
|