Open guerrillalg opened 8 years ago
- Is there any code example, how one can make Javascript-java compatible encryption/decryption?
- Any suggestions on how to troubleshoot this issue?
Your code snippet seems legit. Try to remove leading 0x00
from the RSA modulus part.
- In the RSA_OAEP_SHA256 which MGF parameter is used?
SHA-256 for both hashing and MGF.
Your code snippet seems legit. Try to remove leading 0x00 from the RSA modulus part.
I've tried with and without it - the same.
I've tried the following: Java:
Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding"); JS: asmCrypto.RSA_OAEP_SHA1.encrypt("abc", key, "");
And it worked. So, I guess, the problem is:
SHA-256 for both hashing and MGF.
By default Java supports the following RSA algorithms:
RSA/ECB/PKCS1Padding (1024, 2048) RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048) RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)
So, now the question is, is there possibility to configure MGF in JS library? And could you point, where is it performed?
SO, proceeding with some tests, I've got it working: JS code:
enc = asmCrypto.RSA_OAEP_SHA256.encrypt("abc", key, "");
And Java:
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPPadding"); OAEPParameterSpec oaepParams = new OAEPParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-256"), PSource.PSpecified.DEFAULT); rsa.init(Cipher.DECRYPT_MODE, key, oaepParams); String decrypted = new String(rsa.doFinal(data));
The problem is that by default "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" algorithm is using SHA-1 For MGF1, regardless that SHA-256 is provided for hashing.
So, it would be nice to have ability to config Hash for MGF separately.
I want to encrypt using RSA_OAEP_SHA256 on JavaScript side
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/asmCrypto/0.22.0/asmcrypto.all.js"></script>
var encrypted = asmCrypto.RSA_OAEP_SHA256.encrypt(stringToBeEncrypted, pubkey, "");
getting error: Uncaught TypeError: Cannot read property 'encrypt' of undefined
Do you know the solution or any example that would help? Thanks
Hi. I am trying to implement Javascript encryption and Java decryption system.
Javascript part:
Java part:
Key exchange: Key was generated and stored in the keystore. Java loads it directly from it. Next key was extracted to .pem file:
So, when trying to do so, I get:
So the questions are: