Add base64 enc/dec
This commit is contained in:
parent
8ed6eb0a45
commit
6b17df039b
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user