相关疑难解决方法(0)

用Java解码Base64数据

我有一个Base64编码的图像.在Java中解码它的最佳方法是什么?希望仅使用Sun Java 6附带的库.

java base64

463
推荐指数
13
解决办法
71万
查看次数

BASE64Encoder是内部API,可能会在将来的版本中删除

我试图解决这个问题,但我从来没有找到适合我的解决方案.问题是我正在接受有关BASE64Encoder的警告.没有BASE64Encoder,有没有其他方法可以做到这一点?

代码:

public static String Encrypt(String Data) throws Exception 
{
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encVal = c.doFinal(Data.getBytes());
    String encryptedValue = new BASE64Encoder().encode(encVal); //Here is the problem

    return encryptedValue;
}

public static String Decrypt(String encryptedData) throws Exception 
{
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.DECRYPT_MODE, key);
    byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData); //Another problem
    byte[] decValue = c.doFinal(decordedValue);
    String decryptedValue = new String(decValue);

    return decryptedValue;
}

private static Key generateKey() throws Exception 
{ …
Run Code Online (Sandbox Code Playgroud)

java base64 encoding

10
推荐指数
1
解决办法
2万
查看次数

如何将sun.misc.BASE64Encoder转换为org.apache.commons.codec.binary.Base64

我有以下代码sun.misc.BASE64Encoder:

BASE64Decoder decoder = new BASE64Decoder();
byte[] saltArray = decoder.decodeBuffer(saltD);
byte[] ciphertextArray = decoder.decodeBuffer(ciphertext);
Run Code Online (Sandbox Code Playgroud)

并希望将其转换为org.apache.commons.codec.binary.Base64.我已经浏览了API,文档等,但我找不到似乎匹配的东西并给出相同的结果值.

java base64 apache-commons-codec

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

base64 ×3

java ×3

apache-commons-codec ×1

encoding ×1