Skip to content

Custom Base64EncodingTextEncryptor not possible for Encryptors.queryableText()Β #5099

Closed

Description

@ksdev-pl

Hi

When the user wants to store an encrypted text in the database (in text, not binary format) using the available TextEncryptor (for example through Encryptors.delux()), the resultant String is hex-encoded (through HexEncodingTextEncryptor).

Hex-encoding is very inefficient when it comes to size. So the user writes his own Base64EncodingTextEncryptor to use it instead of HexEncodingTextEncryptor, as the Base64 is much more efficient.

It's easy to use such a Base64EncodingTextEncryptor to wrap the default Encryptors methods, like the Encryptor.stronger(). But it's not easily possible (AFAIK) to use the Base64 encoding to wrap a Encryptors.queryableText() method (because it already returns a hex-encoded string, unless we decode the hex-encoded string to encode it again in Base64, which is not the best option).

The problem:

  • there is no possibility to use a TextEncryptor other than HexEncodingTextEncryptor for the "queryable" texts (that is, texts encrypted with empty iv).
  • "queryable" text functionality justifies the empty iv (when it's really needed).

Possible solutions:

  • public AesBytesEncryptor (so we can wrap it with custom TextEncryptor - when using empty iv)
  • something like noIvText method in Encryptors (so we can wrap an Encryptors empty iv method with custom TextEncryptor)

Or is there another possibility?

Activity

  1. ksdev-pl commented on Mar 10, 2018

    @ksdev-pl
    ContributorAuthor

    Another simple solution:

    public static BytesEncryptor queryable(CharSequence password, CharSequence salt) {
    	return new AesBytesEncryptor(password.toString(), salt);
    }

    Having an additional queryable method which returns a BytesEncryptor, the user can wrap it in any custom TextEncryptor he wants - he's no longer limited to HexEncodingTextEncryptor.

  2. added a commit that references this issue on Nov 13, 2018
  3. added this to the 5.2.0.M1 milestone on Nov 14, 2018
  4. self-assigned this
    on Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: cryptoAn issue in spring-security-cryptotype: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions