Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 2.47 KB

File metadata and controls

68 lines (49 loc) · 2.47 KB

Sql server encryption toolkit

Java CI with Maven

This library provides encryption and decryption functionalities for data, designed to mimic the encryption behavior of SQL Server.

Features

  • Encryption: Encrypt sensitive data using the same encryption algorithm and parameters as SQL Server.
  • Decryption: Decrypt data encrypted using SQL Server-compatible encryption.
  • Integration with Spring Boot: Easily integrate encryption and decryption into your Spring Boot applications.

Installation

You can include this library in your Spring Boot project by adding the following dependency to your pom.xml:

<dependency>
    <groupId>cz.matmar</groupId>
    <artifactId>sql-server-encryption-toolkit</artifactId>
    <version>latest</version>
</dependency>

Usage

Encryption

To encrypt data, simply use the SQLServerEncryptionService provided by this library:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MyService {

    @Autowired
    private SQLServerEncryptionService encryptionService;

    public HexString encryptData(String passphrase, String plaintext) {
        return encryptionService.EncryptByPassPhrase(passphrase, plaintext, CipherVersion.V2);
    }
}

Decryption

To decrypt data, you can use the same encryptionService instance:

public String decryptData(String passphrase, String ciphertext) {
    return encryptionService.DecryptByPassPhrase(passphrase, ciphertext, true, false);
}

Message Structure (V2)

Field Size Description
Prefix 1B Numeric prefix
Version 1B Version number
Reserve 3B Reserved bytes
IV 16B Initialization Vector for encryption
Magic Number 4B Identification number for validation
Integrity Bytes 2B Checksum for data integrity verification
Plaintext Length 2B Length of the plaintext following the header
Plaintext 48B Data encrypted with the given parameters