Encryptor
class Encryptor(val encryptFn: (String) -> String, val decryptFn: (String) -> String, val maxColLengthFn: (Int) -> Int)
Base cipher class responsible for the encryption and decryption of data.
Samples
import org.springframework.security.crypto.encrypt.AesBytesEncryptor
import org.springframework.security.crypto.keygen.KeyGenerators
import org.springframework.security.crypto.util.EncodingUtils
import java.util.*
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
import kotlin.math.ceil
fun main() {
//sampleStart
return AesBytesEncryptor(
password.toString(),
salt,
KeyGenerators.secureRandom(AES_256_GCM_BLOCK_LENGTH),
AesBytesEncryptor.CipherAlgorithm.GCM
).run {
Encryptor(
{ base64Encoder.encodeToString(encrypt(it.toByteArray())) },
{ String(decrypt(base64Decoder.decode(it))) },
{ inputLen ->
base64EncodedLength(AES_256_GCM_BLOCK_LENGTH + inputLen + AES_256_GCM_TAG_LENGTH)
}
)
}
//sampleEnd
}
Constructors
Properties
Functions
Link copied to clipboard
Returns the maximum column length needed to store an encrypted value, using the specified inputByteSize, and determined by maxColLengthFn.