DES and 3DES encryption in Swift

DES and 3DES encryption in Swift

Description

DES and 3DES are unsuitable for modern protection of sensitive data because of their small block size and outdated design.

Potential impact

  • Increased exposure to cryptanalysis and brute-force attacks.
  • Greater risk of sensitive data recovery.
  • Failure to meet applicable requirements while relying on legacy encryption.

Remediation

  • Replace DES or 3DES with authenticated encryption such as AES-GCM. Migrate stored data to a new format with a new key.
  • Isolate any legacy compatibility code from sensitive-data processing until you can retire it. Generate keys, IVs and nonces with secure randomness and follow your key-management policy.

Examples

Before

The first excerpt uses CryptoSwift, the second CryptoKit. Imports and key preparation are omitted. The two libraries use different key types.

swift
let des = try DES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7)

After

swift
let sealedBox = try AES.GCM.seal(data, using: key)

AES.GCM.seal encrypts and authenticates data with a CryptoKit SymmetricKey.

References