spring-projects / spring-projects/spring-security

The default initialization vector size of the AesBytesEncryptor should be 12 bytes for GCM

Open
#3,879 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Summary

When trying to decrypt data with Node.js (AES256, GCM), I realized the initialization vector was of 12 bytes while it's 16 bytes length in the AesBytesEncryptor: https://github.com/spring-projects/spring-security/blob/master/crypto/src/main/java/org/springframework/security/crypto/encrypt/AesBytesEncryptor.java#L63

The spec recommends to use initialization vectors of 96 bits length: http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf

An initialization vector IV , that can have any number of bits between 1 and 264. For a fixed
value of the key, each IV value must be distinct, but need not have equal lengths. 96-bit
IV values can be processed more efficiently, so that length is recommended for situations in
which efficiency is critical.

Actual Behavior

Default size of the initialization vector for GCM cipher algorithm: 16 bytes

Expected Behavior

Default size of the initialization vector for GCM cipher algorithm: 12 bytes. Use: KeyGenerators.secureRandom(12).

Version

4.0.2.RELEASE

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with crypto/src/main/java/org/springframework/security/crypto/encrypt/AesBytesEncryptor.java at the initialization-vector setup referenced in the issue. Check the current default and the KeyGenerators.secureRandom call, then verify that GCM uses a 12-byte default initialization vector as described in the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
cryptography, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.