问题描述
我想使用带有公钥的RSA加密javascript中的一个小字符串,然后使用私钥在java服务器端代码中解密该字符串。
I want to encrypt a small string in javascript using RSA with public keys and then decrypt that string in java server side code using private keys.
我正在使用javascript代码:
示例:
I am using this code in javascript:http://www-cs-students.stanford.edu/~tjw/jsbn/Example at:http://www-cs-students.stanford.edu/~tjw/jsbn/rsa2.html
并且这个java代码代码:
and this code on java side:Encrypting string in javascript and decryption in java
这两个代码都能独立工作,但彼此不了解。今天需要解决这个问题,或者我可以接受任何其他非对称算法。
Both of codes work good independently but they do not understand each other. Need to solve this today or I am open to accept any other asymmetrical algorithm that works this way.
推荐答案
您正在使用原始加密在Java端和使用PKCS#1 v1.5填充在Java卡端的RSA加密。您应该通过 javax.crypto.Cipher.getInstance(RSA / None / PKCS1Padding)
尝试使用Java RSA。如果存在,不要忘记删除任何基本的64编码。
You are using raw encryption on the Java side and RSA encryption using PKCS#1 v1.5 padding on the Java Card side. You should try and use Java RSA through the javax.crypto.Cipher.getInstance("RSA/None/PKCS1Padding")
. Don't forget to remove any base 64 encoding if that is present.
这篇关于在JavaScript中使用RSA加密一个小字符串,然后在服务器上的java中解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!