bool isBase64(String str) { try { // Try to decode the string and check if it produces valid UTF-8 utf8.decode(base64.decode(str)); return true; } catch (e) { return false; } }