Commit f9245dc9 authored by dankl's avatar dankl

Derived AndroidBase64Service from IBase64Service

parent cea705bd
package net.dankito.utils.android.hashing
import android.util.Base64
import net.dankito.utils.hashing.IBase64Service
import java.nio.charset.Charset
class AndroidBase64Service {
class AndroidBase64Service : IBase64Service {
companion object {
val DefaultCharset: Charset = Charset.forName("UTF-8")
}
override fun encode(stringToEncode: String): String {
return encode(stringToEncode.toByteArray(IBase64Service.DEFAULT_CHAR_SET))
}
fun encode(stringToEncode: String, charset: Charset = DefaultCharset): String {
return encode(stringToEncode.toByteArray(charset))
}
fun encode(dataToEncode: ByteArray): String {
override fun encode(dataToEncode: ByteArray): String {
return Base64.encodeToString(dataToEncode, Base64.NO_WRAP)
}
override fun decode(stringToDecode: String): String {
return String(decodeToBytes(stringToDecode), IBase64Service.DEFAULT_CHAR_SET)
}
fun decode(stringToDecode: String, charset: Charset = DefaultCharset): String {
return String(decodeToBytes(stringToDecode), charset)
}
fun decodeToBytes(stringToDecode: String): ByteArray {
override fun decodeToBytes(stringToDecode: String): ByteArray {
return Base64.decode(stringToDecode, Base64.NO_WRAP)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment