![JAR search and dependency download from the Maven repository](/logo.png)
io.justdevit.kotlin.boost.encryption.Decrypter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boost-commons Show documentation
Show all versions of boost-commons Show documentation
Library to boost working with Kotlin/JVM projects.
The newest version!
package io.justdevit.kotlin.boost.encryption
import io.justdevit.kotlin.boost.base64.decode
import io.justdevit.kotlin.boost.base64.isBase64
/**
* Represents an interface for decrypting encrypted texts.
*/
interface Decrypter {
/**
* Decrypts the given [EncryptedText].
*
* @param value The encrypted text to decrypt.
* @return The decrypted raw text.
*/
fun decrypt(value: EncryptedText): RawText = RawText(decrypt(value.value))
/**
* Decrypts the given encrypted value.
*
* @param value The encrypted value to decrypt.
* @return The decrypted value.
*/
fun decrypt(value: String): String {
var clearedValue = value
if (clearedValue.startsWith(ENCRYPTED_DATA_PREFIX)) {
clearedValue = clearedValue.substring(ENCRYPTED_DATA_PREFIX.length)
}
val bytes = if (clearedValue.isBase64()) clearedValue.toByteArray().decode() else clearedValue.toByteArray()
return String(decrypt(bytes))
}
/**
* Decrypts the given byte array.
*
* @param bytes The byte array to decrypt.
* @return The decrypted byte array.
*/
fun decrypt(bytes: ByteArray): ByteArray
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy