I am trying to check my input string is already encoded or not. But getting "true" for "123456", "admin123".
new String(Base64.getDecoder().decode(inputStr), StandardCharsets.UTF_8);
public class AppTest {
public static void main(String[] args) {
String inputStr = "admin123";
System.out.println("isEncoded: " + isEncoded(inputStr));
}
private static boolean isEncoded(String inputStr) {
try {
new String(Base64.getDecoder().decode(inputStr), StandardCharsets.UTF_8);
return true;
} catch (Exception e) {
return false;
}
}
}
Could you please help me to check any alternate code to check my input string either encoded or not?