无法解析符号BASE64Decoder(Java版本9.0.1) [英] Cannot resolve symbol BASE64Decoder (Java version 9.0.1)

查看:345
本文介绍了无法解析符号BASE64Decoder(Java版本9.0.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我以Base64格式返回加密或解密的字符串时,它可以t resolve BASE64Encoder()and BASE64Dencoder()`.我该如何解决?

When I return encrypted or decrypted string in Base64 format it cant resolveBASE64Encoder()andBASE64Dencoder()`. How can I resolve it?

import javax.crypto.*;
import java.io.*;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

class DesEncrypter {
    Cipher ecipher;
    Cipher dcipher;

public DesEncrypter(SecretKey key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
    ecipher = Cipher.getInstance("DES");
    dcipher = Cipher.getInstance("DES");
    ecipher.init(Cipher.ENCRYPT_MODE, key);
    dcipher.init(Cipher.DECRYPT_MODE, key);
}

public String encrypt(String str) throws UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException {
    byte[] utf8 = str.getBytes("UTF8");
    byte[] enc = ecipher.doFinal(utf8);
    return new sun.misc.BASE64Encoder().encode(enc);
}

public String decrypt(String str) throws IOException, IllegalBlockSizeException, BadPaddingException {
    byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
    byte[] utf8 = dcipher.doFinal(dec);
    return new String(utf8, "UTF8");
}

}

推荐答案

通常不应使用sun.misc.这些类是JDK的内部组件,可以用Java的新版本删除(如此处所述).

You should not use sun.misc in general. Those classes are internal to the JDK and may be removed with new versions of Java (as happened here).

我建议使用第三方库,例如Apache Codecs.有许多实用程序类使您不必执行列出的任何代码.

I recommend using a third party library like Apache Codecs. There are a bunch of utility classes that would make it unneccessary to do any of the code you listed.

站点: https://commons.apache.org/proper/commons-codec/

文档: https://commons.apache.org/proper/commons-codec/archives/1.11/apidocs/org/apache/commons/codec/binary/Base64.html

这篇关于无法解析符号BASE64Decoder(Java版本9.0.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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