CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework-security--spring-security-crypto

Spring Security Crypto provides cryptographic utilities including password encoding, key generation, encryption, and various hashing functions

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Spring Security Crypto

Spring Security Crypto provides a comprehensive suite of cryptographic utilities for Spring Security applications, including secure password encoding algorithms, key generation utilities, encryption/decryption services, and various encoding/decoding functions. The library is designed with security best practices and provides industry-standard cryptographic implementations.

Package Information

  • Package Name: spring-security-crypto
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-crypto</artifactId>
      <version>6.5.1</version>
    </dependency>

Core Imports

// Password encoding
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.BCryptPasswordEncoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;

// Encryption
import org.springframework.security.crypto.encrypt.BytesEncryptor;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.crypto.encrypt.Encryptors;

// Key generation
import org.springframework.security.crypto.keygen.BytesKeyGenerator;
import org.springframework.security.crypto.keygen.StringKeyGenerator;
import org.springframework.security.crypto.keygen.KeyGenerators;

// Codec utilities
import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.crypto.codec.Hex;
import org.springframework.security.crypto.codec.Utf8;
import org.springframework.security.crypto.util.EncodingUtils;

Basic Usage

import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.crypto.keygen.KeyGenerators;
import org.springframework.security.crypto.keygen.StringKeyGenerator;

// Password encoding
PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
String encodedPassword = passwordEncoder.encode("mySecretPassword");
boolean matches = passwordEncoder.matches("mySecretPassword", encodedPassword);

// Text encryption
TextEncryptor textEncryptor = Encryptors.text("myPassword", "mySalt");
String encrypted = textEncryptor.encrypt("Hello World");
String decrypted = textEncryptor.decrypt(encrypted);

// Key generation
StringKeyGenerator keyGenerator = KeyGenerators.string();
String generatedKey = keyGenerator.generateKey();

Architecture

Spring Security Crypto is organized around several key components:

  • Password Encoding: Secure password hashing with multiple algorithm support (BCrypt, Argon2, SCrypt, PBKDF2)
  • Encryption Services: Symmetric encryption for both text and binary data using AES and RSA
  • Key Generation: Secure random key generation for cryptographic operations
  • Codec Utilities: Base64, Hex, and UTF-8 encoding/decoding functions
  • Factory Pattern: Convenient factory classes for creating pre-configured instances
  • Delegation Pattern: Flexible encoder selection based on algorithm identifiers

Capabilities

Password Encoding

Secure password hashing with support for multiple industry-standard algorithms including BCrypt, Argon2, SCrypt, and PBKDF2.

interface PasswordEncoder {
    String encode(CharSequence rawPassword);
    boolean matches(CharSequence rawPassword, String encodedPassword);
    default boolean upgradeEncoding(String encodedPassword);
}

Password Encoding

Encryption and Decryption

Symmetric encryption services for both text and binary data using AES and RSA algorithms with various cipher modes.

interface BytesEncryptor {
    byte[] encrypt(byte[] byteArray);
    byte[] decrypt(byte[] encryptedByteArray);
}

interface TextEncryptor {
    String encrypt(String text);
    String decrypt(String encryptedText);
}

Encryption and Decryption

Key Generation

Secure random key generation utilities for creating cryptographic keys and salts.

interface BytesKeyGenerator {
    int getKeyLength();
    byte[] generateKey();
}

interface StringKeyGenerator {
    String generateKey();
}

Key Generation

Codec Utilities

Encoding and decoding utilities for Base64, Hexadecimal, and UTF-8 conversions.

class Base64 {
    static byte[] encode(byte[] src);
    static byte[] decode(byte[] src);
    static boolean isBase64(byte[] bytes);
}

class Hex {
    static char[] encode(byte[] bytes);
    static byte[] decode(CharSequence hexString);
}

class Utf8 {
    static byte[] encode(CharSequence string);
    static String decode(byte[] bytes);
}

class EncodingUtils {
    static byte[] concatenate(byte[]... arrays);
    static byte[] subArray(byte[] array, int beginIndex, int endIndex);
}

Codec Utilities

docs

codecs.md

encryption.md

index.md

key-generation.md

password-encoding.md

tile.json