Stack Exchange
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character
I am getting below error , i am using below code to generate random code using Java in BeanShell preprocessor in Jmeter -
import java.util.Random;


chars = "1234567890abcdefghiklmnopqrstuvwxyz-";
int string_length = 353;
randomstring ="";

for (int i=0; i < string_length; i++) {
  Random randomGenerator = new Random();
  int randomInt = randomGenerator.nextInt(chars.length());
  randomstring += chars.substring(randomInt,randomInt+1);
}
print(randomstring);
vars.put("RANDOM_STRING",randomstring);

System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
How to resolve this ?
I am getting this -
/abc/FileUpload.ashx?code=k9ttysg0rcv27wptb5y5wdfzzunm346k0rreggc4vd0y003xu-3zpzanqvgyal7i3iqdq91iba7bl4288-xr5u2fspq7wfys9utpltolkmiybv1yttc92a5phw-7i0yh4iw0xc-8w3opy59fumofhzm9m205amvr31d0od-x47xqfii4ymbfxeyp3o54w034t2xowsfumg2pgzpy5qd32u0v7tiqesidn3g9v82168dlegg2e47-a9r8ga0igchfvx63ecw2bdl14zaydif9q1zg-6i1byp9pnr6v174apbix8bcvlu21-ryeiwxom0bmpdpzfhonynte8bcumhk8bqwqxaag9lno&isuploadallowed=1,System.FormatException: The input 

The posted code should not give that error, since you're not doing anything with base64 here. But: if you're using the generated string somewhere else and trying to decode it as if it's base64-encoded, the string shouldn't contain a ! character.

@rickdenhaan : I have updated above, please have a look

@user662285 Please edit your question to include a [mcve], which can be compiled and tested by others. Also note that - is not a valid character for base64 (but it is for base64url).

You can simply Use RandomString.
${__RandomString(353,123456789abcdefghijklmnopqrstuvwxyz,)}

where arguments are string length, string range & output variable(optional)
