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

查看:48
本文介绍了包 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).Code Assists 处理类型并展开 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.

我尝试清理项目、重建项目、将源文件复制到全新的企业项目并以管理员身份运行 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 包.

Note from the future: in Java 8, there is a 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 创建一个 解码器编码器.支持以下类型的编码器和解码器:

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:

  • 基本 - 使用 RFC 4648 和 RFC 2045 的表 1 中指定的Base64 字母表"进行编码和解码操作.编码器不添加任何换行(行分隔符)字符.解码器拒绝包含 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 和文件名安全 - 使用 RFC 4648 表 2 中指定的URL 和文件名安全 Base64 字母表"进行编码和解码.编码器不添加任何换行(行分隔符)字符.解码器拒绝包含 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 - 使用 RFC 2045 表 1 中指定的The Base64 Alphabet"进行编码和解码操作.编码输出必须以每行不超过 76 个字符的行表示,并使用回车 ' ' 后跟换行符 ' ' 作为行分隔符.没有行分隔符添加到编码输出的末尾.在解码操作中忽略所有在 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 ' ' followed immediately by a linefeed ' ' 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.

因此,例如,这是如何创建一个基本的编码器并对 byte 数组进行编码:

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天全站免登陆