Oti*_*Nai 3 java base64 encoding
我有一个字符串String x = "Sample text";,我想打印它的base64加密.正如众多例子所述,我使用:
byte[] encodedBytes = Base64.encodeBase64(x.getBytes());
System.out.println("encodedBytes " + new String(encodedBytes));
Run Code Online (Sandbox Code Playgroud)
但这给了我The method encodeBase64(byte[]) is undefined for the type Base64......为什么?
Anu*_*oob 10
该encode方法属于Base64.Encoder您可以通过运行获得的类Base64.getEncoder().
byte[] encodedBytes = Base64.getEncoder().encode(x.getBytes());
Run Code Online (Sandbox Code Playgroud)
同样,解码:
String originalString = new String(Base64.getDecoder().decode(encodedBytes));
Run Code Online (Sandbox Code Playgroud)
检查出的Base64的javadoc获得更多信息.