This library provides encryption and decryption functionalities for data, designed to mimic the encryption behavior of SQL Server.
- 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.
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>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);
}
}To decrypt data, you can use the same encryptionService instance:
public String decryptData(String passphrase, String ciphertext) {
return encryptionService.DecryptByPassPhrase(passphrase, ciphertext, true, false);
}| 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 |