I use this code in C#.net to send challenge to web page.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
Byte[] rnd = new Byte[64];
rng.GetBytes(rnd);
hidChallenge.Value = Encoding.Unicode.GetString(rnd);
And I in java script use of it.
var base64str = document.getElementById("<%=hidChallenge.ClientID %>");
When run and debug:
base64str = 感≗좦短䗅燛梻脕冔춇噙풣訋詇蹘᧩쾏휇늸䫐顨◣希ࠟ䠎ᐷ
But in java (JSP)
I use this code:
Random r = new Random();
byte[] rndbyte = new byte[64];
r.nextBytes(rndbyte);
String challenge = new String(rndbyte,StandardCharsets.UTF_16LE);
session.setAttribute("challenge", challenge);
And in javascript:
var base64str = 퓻�ꦖ쁳春꼪ꝝ䣇͋ꟼ鱐䆺㺪᠁郷̣攺줶ꋏ歮㏹㬎ꢔ崬魔弝孓翊
I try follow charset also:
US_ASCII
UTF_8
UTF_16
So I get base 64 string error.