Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal key size in Play Framework with java 1.7.0_45 #8

Closed
burczyk opened this issue Mar 18, 2014 · 2 comments
Closed

Illegal key size in Play Framework with java 1.7.0_45 #8

burczyk opened this issue Mar 18, 2014 · 2 comments

Comments

@burczyk
Copy link

burczyk commented Mar 18, 2014

I tried to integrate JNCryptor in Play Framework 2.2 application but I get following exception

org.cryptonode.jncryptor.CryptorException: Caught InvalidKeyException. Do you have unlimited strength jurisdiction files installed?
    at org.cryptonode.jncryptor.AES256JNCryptor.encryptData(AES256JNCryptor.java:334)
    at org.cryptonode.jncryptor.AES256JNCryptor.encryptData(AES256JNCryptor.java:353)
    at controllers.Application.crypto(Application.java:24)
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.apply(routes_routing.scala:61)
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.apply(routes_routing.scala:61)
    at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183)
    at play.core.Router$Routes$$anon$1.invocation(Router.scala:377)
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56)
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91)
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90)
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:278)
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:274)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
    at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.security.InvalidKeyException: Illegal key size
    at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1024)
    at javax.crypto.Cipher.implInit(Cipher.java:790)
    at javax.crypto.Cipher.chooseProvider(Cipher.java:849)
    at javax.crypto.Cipher.init(Cipher.java:1348)
    at javax.crypto.Cipher.init(Cipher.java:1282)
    at org.cryptonode.jncryptor.AES256JNCryptor.encryptData(AES256JNCryptor.java:321)
    ... 21 more

I use Oracle's 1.7.0 JDK on OS X system. I used exactly your example, so my Application.java file looks like this:

package controllers;

import play.Logger;
import play.mvc.*;
import views.html.*;

import org.cryptonode.jncryptor.*;

public class Application extends Controller {

    public static Result index() {
        return ok(index.render("Your new application is ready."));
    }

    public static Result crypto() {

        JNCryptor cryptor = new AES256JNCryptor();
        byte[] plaintext = "Hello, World!".getBytes();
        String password = "secretsquirrel";

        Logger.debug("password length: " + password.toCharArray().length + "\n");

        try {
            byte[] ciphertext = cryptor.encryptData(plaintext, password.toCharArray());
            return ok(new String(ciphertext));
        } catch (CryptorException e) {
            e.printStackTrace();
        }

        return ok("Not encrypted :(");
    }

}

Did anyone try to integrate JNCryptor with Play Framework and Java 1.7 and had similar issue?

@rnapier
Copy link
Member

rnapier commented Mar 18, 2014

@burczyk
Copy link
Author

burczyk commented Mar 19, 2014

Thanks, tips from your link http://suhothayan.blogspot.com/2012/05/how-to-install-java-cryptography.html worked.
I think you can add it to your readme. Two points are crucial:

  1. Download those policy libraries for you java version,
  2. Place them inside jre\lib\security directory and not jdk\lib\security. Those files exist there, but they are not valid, so you have to overwrite them.

Thanks again for your help :)

@burczyk burczyk closed this as completed Mar 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants