aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/Base64Util.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util/Base64Util.kt')
-rw-r--r--src/main/kotlin/util/Base64Util.kt20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main/kotlin/util/Base64Util.kt b/src/main/kotlin/util/Base64Util.kt
index c39c601..0b7b3ea 100644
--- a/src/main/kotlin/util/Base64Util.kt
+++ b/src/main/kotlin/util/Base64Util.kt
@@ -1,17 +1,23 @@
-
package moe.nea.firmament.util
import java.util.Base64
object Base64Util {
fun decodeString(str: String): String {
+ return decodeBytes(str).decodeToString()
+ }
+
+ fun decodeBytes(str: String): ByteArray {
return Base64.getDecoder().decode(str.padToValidBase64())
- .decodeToString()
}
- fun String.padToValidBase64(): String {
- val align = this.length % 4
- if (align == 0) return this
- return this + "=".repeat(4 - align)
- }
+ fun String.padToValidBase64(): String {
+ val align = this.length % 4
+ if (align == 0) return this
+ return this + "=".repeat(4 - align)
+ }
+
+ fun encodeToString(bytes: ByteArray): String {
+ return Base64.getEncoder().encodeToString(bytes)
+ }
}