0

I have been using jCryption for a secure login. On the client i am using the JavaScript package and on the Java decryption i am using BouncyCastle jar to decrypt.

The problem is that it works OK in Tomcat but when i take the same webapp and deploy on Jboss i am having problems loading the BouncyCastle jar.

My question is: is there a way to encrypt using jCryption that will produce a more standardized RSA output which will allow me to use other security providers?

neubert
  • 15,947
  • 24
  • 120
  • 212
special0ne
  • 6,063
  • 17
  • 67
  • 107

3 Answers3

0

Here is the snippet for RSA decoding compatible with jCryption. We assume that encExternalKey is what jCryption send in key parameter on handshake call. modulus and secretExponent are taken from 100_1024_keys.inc.php file that comes with jCryption.

RSAPrivateKeySpec privateKeySpec =
   new RSAPrivateKeySpec(new BigInteger(modulus, 10), new BigInteger(secretExponent, 10));
RSAPrivateKey privateKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(privateKeySpec);

Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
StringBuilder externalKeyBuf =
    new StringBuilder(new String(cipher.doFinal(new BigInteger(encExternalKey, 16).toByteArray())));
String externalKey = externalKeyBuf.reverse().toString().trim();
AlexZam
  • 1,147
  • 7
  • 18
0

jcryption isn't as secure as you might think:

http://www.securityfocus.com/archive/1/520683

My recommendation... do something similar to this:

http://www.frostjedi.com/terra/dev/rsa/index.php

The following URL elaborates:

http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=33024&start=0

neubert
  • 15,947
  • 24
  • 120
  • 212
  • The alternative to jcryption you're suggesting still have potential problems, in particular, the user has little guarantee that the code delivered came from the server (and not a MITM attacker). – Bruno Mar 29 '12 at 16:35
  • True, but that can be mitigated somewhat as well. Quoting the phpbb.com link: "The RSA public key is transmitted in the javascript used to perform the RSA encryption. In theory, this public key could be cached by a Firefox plugin or something and used to verify the identity of the server, however, in lieu of such a plugin, identity verification is not possible." There's also HTML5 storage as well. At that point the initial connection can be spoofed, but then, that's a problem with SSH, too. SSH caches the server host key upon the initial connection. – neubert Apr 02 '12 at 04:09
  • although not everyone does it, you're actually meant to verify the server's signature upon initial connection (provided you can verify it by some other means, e.g. if the admin has given it to you). The main problem is that there is nothing in the browser's UI (i.e. something that's not controlled by the page itself) to help you find out whether the JS is good/bad. This could be mitigated by a plugin indeed. – Bruno Apr 02 '12 at 08:54
0

Generally speaking, if you want security, avoid JavaScript cryptography, use SSL/TLS instead.

The main problems are:

  • insufficient quality of implementation of cryptographic routines (e.g. random numbers)
  • the client has no idea whether the script may have been tampered with by a MITM attacker, even if the JavaScript library is of sufficient quality.

You're not actually adding much security by using JavaScript cryptography on your website unfortunately.

Bruno
  • 119,590
  • 31
  • 270
  • 376