又没有考虑编码的问题?
或者空串或者空格(trim)?
或者空串或者空格(trim)?
解决方案 »
- 编译spark报错
- 我想实现单击 查询书库 子节点后 弹出一个新窗体 我查了很多方法 因为不是很熟悉 总是实现不了 麻烦帮我看看怎么改 谢谢
- 解析xml的一个问题
- java中int类型数据的范围
- 完全圣诞树代码。。。。。
- 请问java里有没动态二维数组概念,如何定义
- Help me!
- java API中有一个indexOf(String str, int fromIndex) 函数,其中的int参数是做什么用的?
- 关于Java中调用的问题!
- 怎样用JAVA得到中文姓名的首字母缩写?李四返回的结果为LS
- 如何搭建java开发环境?
- 菜m提问!我想做一个下凹的框框,然后里边放置一些按钮? JAVA中可以做吗?
我在用RSA做类似的功能时碰到过,我是转换成16进制字符串传递的,如果密文字节数组的第一个元素<15,那么十六进制表示是0f,0被自动丢掉了
javax.mail.internet.MimeUtility有encode和decode method实现
sun.misc.BASE64Decoder
import java.security.*;
import javax.crypto.*;public class DesedeEx
{ public static void main(String args[])throws Exception
{ //加密过程。
KeyGenerator genkey=KeyGenerator.getInstance("Desede");
genkey.init(168);
Key mykey=genkey.generateKey( );
System.out.println("Generating the key done....");
System.out.println(mykey); Cipher cipher=Cipher.getInstance("Desede/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE,mykey);
byte []plaintext=text.getBytes("UTF8");
//注意把字符串转换成字节需要指定编码方式,一般用此“UTF8”。
byte[] ciphertext=cipher.doFinal(plaintext);//密文。
//解密过程。很简单阿。
cipher.init(Cipher.DECRYPT_MODE,mykey);
byte[] decryptedText=cipher.doFinal(ciphertext);
String output=new String(decryptedText,"UTF8");
//此处指定编码方式了哈哈。肯定行的。
System.out.println("\n\nDecrypted text:"+output);
}
}
我也碰到了一样的问题。
加密后得到的byte[]转换成字符串后,写到一个html的超链上,但是下一个服务程序得到后解密时总是出错,错误如上。up说的方法在加密后没有转换成字符串。
String cipherString=enc.encode(ciphertext);BASE64Decoder dec=new BASE64Decoder();
ciphertext=dec.decode(cipherString);