我想知道是否有人知道任何库在javascript中执行加密并在java中解密。我已经尝试了很多API,但是在java中并没有得到相同的值。
我想公私钥加密,因此尝试使用RSA。 几个我已经使用是:我检查在javascript中加密字符串和在java中解密
- http://www-cs-students.stanford.edu/~tjw/jsbn/
- http://ats.oka.nu/titaniumcore/js/crypto/readme.txt
- http://www.ohdave.com/rsa/
很少的事情,JavaScript的突破字符串成小块,然后进行加密,这使得在Java中密文不同和JavaScript。我编辑的JavaScript代码使用字符串作为一个整体,但没有奏效。
我也尝试将html页面的charset设置为utf-8,但它也不起作用。 我成功地加密了像'K'这样的单个字符串,并且正确地加密和解密,这让我认为在JavaScript中将字符串分成小块(我检查过,整个)。
我的Java实现:
BigInteger d = new BigInteger("1f3fac65c4ae222e3a3074dd4c38fbb72c0705c4bbac0385b867c12c25a44e01", 16);
BigInteger e = new BigInteger("65537");
BigInteger N = new BigInteger("b42e91fbca364cf2a125aec67ffbdab624fd401100c40ea05189ba34d1028b0d", 16);
String messageToEncrypt = "kishor";
byte [] messageByte = messageToEncrypt.getBytes();
BigInteger message = new BigInteger(messageByte);
//Encrypting and Decrypting messages
//Encrypt a message using N and e:
BigInteger ciphertext = message.modPow(e, N);
//Decrypt the message using N and d:
BigInteger plaintext = ciphertext.modPow(d, N);
byte[] plainTextByte = plaintext.toByteArray();
String decryptMessage = new String(plainTextByte);
/*System.out.println("p : " + p);
System.out.println("q : " + q);*/
System.out.println("N : " + N.toString(16));
System.out.println("e : " + e.toString(16));
System.out.println("d : " + d.toString(16));
/*System.out.println("PhiN : " + PhiN);*/
System.out.println("ciphertext : " + ciphertext.toString(16));
System.out.println("decryptMessage : " + decryptMessage);
}
请让我知道,如果我已经搜查了许多问题(在计算器本身),但无法找到一个解决方案是可能的。
那么,你想在JS方加密并在java方解密?你如何将加密数据从一个传递给另一个? – maasg 2012-07-31 09:55:12
密文将被传递,解密将使用私钥。 – 2012-07-31 09:56:56
你如何在javascript和java之间传输数据?你能展示Javascript方面吗? – maasg 2012-07-31 09:59:50