Access restriction: The type 'BASE64Decoder' is not API (restriction on required library xxx)

简介: 版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/79913071 ...
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/79913071

Access restriction: The type 'BASE64Decoder' is not API (restriction on required library xxx)


有人可能遇到的是一个错误,

也可能是一个提示!


在类中使用了 

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

就会遇到这个问题。

问题原因:

参考:https://stackoverflow.com/questions/44268690/access-restriction-the-type-base64decoder-is-not-api

所有sun。*和com.sun。*软件包对Java实现都是私有的。任何未来的Java版本都可能会改变它们,可能会破坏依赖它们的应用程序代码。相比之下,java。*,javax。*和javafx。*软件包中的所有类都被设置为一成不变。他们的名字和公众成员不会改变,也不会被删除(理论上,已弃用的除外)。这就是为什么你会得到一个消息,说明这些类不是公共API的一部分。它们不适合公共消费。从Java 8开始,您应该使用java.util.Base64。但是,它看起来像使用Java 7,因此您需要使用DatatypeConverter.parseBase64Binary和DatatypeConverter.printBase64Binary。还应该提到的是,预计将于2017年7月发布的Java 9将不允许程序访问sun。*课程。请参阅https://mreinhold.org/blog/jigsaw-module-system。

解决方法:

改用 java.util.Base64,例如:

String hash = new String(Base64.getEncoder().encode(raw));
return new String(Base64.getEncoder().encode(rawString.getBytes(charsetName))); 
return new String(Base64.getDecoder().decode(encrypted.getBytes(charsetName)));

目录
相关文章
|
6月前
|
开发者
上传苹果版本时错误解决办法:No suitable application records were found. Verify your bundle identifier
上传苹果版本时错误解决办法:No suitable application records were found. Verify your bundle identifier
60 2
|
Java
The type XXX cannot be resolved. It is indirectly referenced from required .class files
The type XXX cannot be resolved. It is indirectly referenced from required .class files
84 0
No injector for custom defined data type的解决办法
No injector for custom defined data type的解决办法
224 0
No injector for custom defined data type的解决办法
How to resolve warning message Access restriction -The type Resource is not accessible
How to resolve warning message Access restriction -The type Resource is not accessible
116 0
How to resolve warning message Access restriction -The type Resource is not accessible
What happens when passing an non-exist text object to API
What happens when passing an non-exist text object to API
What happens when passing an non-exist text object to API
Cannot find source code based button in SE24 - modification assistant
Cannot find source code based button in SE24 - modification assistant
126 0
|
Oracle 关系型数据库 Linux
ASMFD (ASM Filter Driver) Support on OS Platforms (Certification Matrix). (文档 ID 2034681.1)
1) Starting with Oracle Grid Infrastructure 12C Release 1 (12.1.0.2), Oracle ASM Filter Driver (Oracle ASMFD) is installed with an Oracle Grid Infrastructure installation.
2645 0
|
开发工具 Android开发 Go
RN Exception: Before building your project, you need to accept the license agreements and comp le...
异常 * What went wrong: A problem occurred configuring project ':app'. > You have not accepted the license agreements of the fol...
1617 0