包com.sun.org.apache.xml.internal.security.utils.Base64不存在 [英] Package com.sun.org.apache.xml.internal.security.utils.Base64 does not exist

查看:2112
本文介绍了包com.sun.org.apache.xml.internal.security.utils.Base64不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NetBeans 7.0.1和JDK 1.6 Update 24以及导入包时 com.sun.org.apache.xml.internal.security.utils.Base64 编码密码哈希:

I am using NetBeans 7.0.1 and JDK 1.6 Update 24 and when importing the package com.sun.org.apache.xml.internal.security.utils.Base64 to encode a password hash:

u.setPassword(Base64.encode(digest(password)));

编译时,我收到以下错误:

When compiling however, I get the following error:

(omitted)\RegistrationController.java:8: package com.sun.org.apache.xml.internal.security.utils does not exist
import com.sun.org.apache.xml.internal.security.utils.Base64;

(omitted)\RegistrationController.java:94: cannot find symbol
symbol  : variable Base64
location: class RegistrationController
    u.setPassword(Base64.encode(digest(password)));
2 errors

我已经阅读了有关同一问题的其他几个问题但所有处理包裹的问题这不是JDK的一部分,而这是( rt.jar )。代码辅助工作在类型上,扩展jar显示源代码和二进制文件实际上也存在。

I have read several other questions regarding the same problem but all deal with packages that are not part of the JDK whereas this is (rt.jar). Code Assists works on the type and expanding the jar reveals both the source code and binary are in fact present as well.

我试过清理项目,重建它,复制源文件到一个全新的Enterprise项目并以管理员身份运行NetBeans,但都无济于事。关于如何解决这个问题的任何线索非常感谢!

I have tried cleaning the project, rebuilding it, copying the source files over to a brand new Enterprise project and running NetBeans as Administrator, all to no avail. Any clue on how to solve this very much appreciated!

谢谢!

推荐答案

Greg 在对以前接受的答案


未来的注意事项:在Java 8中,有一个 java.util.Base64 package。

因为它现在作为一部分实现标准Java API,最好使用它而不是Apache Commons Codec。考虑到这一点,我认为这应该作为答案发布。

Since it is now implemented as a part of the standard Java API, it is probably preferable to use it instead of Apache Commons Codec. With this in mind I think this should be posted as an answer.

API中有许多方法 Base64 创建 Decoder 编码 。支持以下类型的编码器和解码器:

The API has a number of methods in the class Base64 to create a Decoder or Encoder. The following types of encoders and decoders are supported:


  • 基本 - 使用Base64字母如RFC 4648和RFC 2045的表1中所规定的用于编码和解码操作。编码器不添加任何换行符(行分隔符)字符。解码器拒绝包含base64字母表之外的字符的数据。

  • Basic - Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.

URL和文件名安全 - 使用URL和文件名安全Base64字母在RFC 4648的表2中指定用于编码和解码。编码器不添加任何换行符(行分隔符)字符。解码器拒绝包含base64字母之外的字符的数据。

URL and Filename safe - Uses the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.

MIME - 使用表中指定的Base64 Alphabet RFC 2045中的1个用于编码和解码操作。编码输出必须以不超过76个字符的行表示,并使用回车符'\ r',然后立即使用换行符'\ n'作为行分隔符。没有行分隔符添加到编码输出的末尾。在解码操作中,将忽略base64字母表中未找到的所有行分隔符或其他字符。

MIME - Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded output must be represented in lines of no more than 76 characters each and uses a carriage return '\r' followed immediately by a linefeed '\n' as the line separator. No line separator is added to the end of the encoded output. All line separators or other characters not found in the base64 alphabet table are ignored in decoding operation.

因此,例如,这是如何创建一个基本编码器并编码字节数组:

So, for example, this is how to create a basic encoder and encode a byte array:

byte[] encodedArray = Base64.getEncoder().encode(someArrayToEncode);

这篇关于包com.sun.org.apache.xml.internal.security.utils.Base64不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆