2015-12-30 68 views
2

警告我被加密一些文字,爲我所用BASE64Encoder訪問限制在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("restriction")禁止這種警告。但我想知道爲什麼我得到這個警告。它會在以後造成問題嗎?

回答

1

您可能正在使用的進口sun.misc.BASE64Encoder;這是在1.8

不贊成你應該用在1.8(https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html)存在新的base64去,或者你可以使用Apache通用編LIB(我使用)

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

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

BASE64Encoder駐留在sun.misc包。正如你使用的1.8版本,即使Oracle不鼓勵使用。在這裏閱讀http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html

摘要從該鏈接: From one release to another, these classes may be removed, or they may be moved from one package to another, and it's fairly likely that their interface (method names and signatures) will change