Static IV/nonce (ARCH2114)
Esta página aún no está disponible en tu idioma.
Key python.security.static-iv · Severity error · Category security · CWE CWE-329
A constant or zero IV/nonce destroys the semantic security of CBC/CTR/GCM modes and causes critical breaks when reused with the same key. Generate a random IV per message.
Incorrect
Section titled “Incorrect”from cryptography.hazmat.primitives.ciphers.aead import AESGCM
def encrypt(key, data): nonce = b"\x00" * 12 return AESGCM(key).encrypt(nonce, data, None)Correct
Section titled “Correct”import osfrom cryptography.hazmat.primitives.ciphers.aead import AESGCM
def encrypt(key, data): nonce = os.urandom(12) return nonce + AESGCM(key).encrypt(nonce, data, None)Generate a cryptographically random, unique IV/nonce for every encryption operation.