diff --git a/TextUtils/src/main/java/eu/mikroskeem/utils/text/TextUtils.java b/TextUtils/src/main/java/eu/mikroskeem/utils/text/TextUtils.java index f76933c..117d79d 100644 --- a/TextUtils/src/main/java/eu/mikroskeem/utils/text/TextUtils.java +++ b/TextUtils/src/main/java/eu/mikroskeem/utils/text/TextUtils.java @@ -2,6 +2,8 @@ package eu.mikroskeem.utils.text; import org.jetbrains.annotations.NotNull; +import java.util.Base64; + public class TextUtils { /** * Check if string contains whitespace @@ -11,4 +13,22 @@ public class TextUtils { public static boolean hasWhitespace(@NotNull String str){ return !str.matches("\\S+"); } + + /** + * Encode string to Base64 (with padding) + * @param str String to encode + * @return Base64 encoded string + */ + @NotNull public static String b64enc(@NotNull String str){ + return Base64.getEncoder().encodeToString(str.getBytes()); + } + + /** + * Decode Base64 to string + * @param b64str Base64 encoded string + * @return Decoded Base64 string + */ + @NotNull public static String b64dec(@NotNull String b64str){ + return new String(Base64.getDecoder().decode(b64str)); + } }