aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/Base64Util.kt
blob: c39c601d1b120db8eb0eb32be51f02cf5b19f431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package moe.nea.firmament.util

import java.util.Base64

object Base64Util {
	fun decodeString(str: String): String {
		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)
    }
}