Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BASE64Encoder上的访问限制警告_Java_Security_Base64 - Fatal编程技术网

Java BASE64Encoder上的访问限制警告

Java BASE64Encoder上的访问限制警告,java,security,base64,Java,Security,Base64,我正在加密一些文本,为此我使用了BASE64Encoder String encryptedValue = new BASE64Encoder().encode(encVal); 但我得到一个警告 The constructor 'BASE64Encoder()' is not API (restriction on required library 'C:\Program Files (x86)\Java\jdk1.8.0_45\jre\lib\rt.jar') The method 'Ch

我正在加密一些文本,为此我使用了
BASE64Encoder

String encryptedValue = new BASE64Encoder().encode(encVal);
但我得到一个警告

The constructor 'BASE64Encoder()' is not API (restriction on required library 'C:\Program Files (x86)\Java\jdk1.8.0_45\jre\lib\rt.jar')
The method 'CharacterEncoder.encode(byte[])' is not API (restriction on required library 'C:\Program Files (x86)\Java\jdk1.8.0_45\jre\lib\rt.jar')
Access restriction: The type 'BASE64Encoder' is not API (restriction on required library 'C:\Program Files (x86)\Java\jdk1.8.0_45\jre\lib\rt.jar')

我可以通过
@SuppressWarnings(“限制”)
来抑制此警告。但我想知道为什么我会收到这个警告。它以后会产生问题吗?

您应该避免调用
sun.
类:

直接调用sun.*包的Java程序不是 保证在所有Java兼容平台上工作。事实上,这样一个 即使在同一个平台上的未来版本中,程序也不能保证工作 站台

其他库(如Apache Commons Codec)将满足您的需要:


您可能正在使用import sun.misc.Base64编码器;这在1.8中已被弃用

您应该使用1.8()上的新base64,也可以使用apache公共编解码器库(我使用的)


BASE64Encoder位于sun.misc包中。因为您使用的是1.8版本,即使是Oracle也不鼓励使用。在这里读

摘自该链接:
从一个版本到另一个版本,这些类可能会被删除,或者它们可能会从一个包移动到另一个包,它们的接口(方法名称和签名)很可能会发生更改

import org.apache.commons.codec.binary.Base64;

    String encryptedValue = new Base64().encodeToString(encVal);