Java: Patching client side security policy from applet for AES256

后端 未结 2 1937
生来不讨喜
生来不讨喜 2020-12-17 03:18

I require AES256 encryption/decryption in a commercial web application. Currently everything is good with a key size of 128. This is not satisfactory cryptographically so my

相关标签:
2条回答
  • 2020-12-17 03:53

    You are either stuck with the weak encryption or a potentially problematic step for users if you stick to the SunJCE.

    There is obviously no problem importing an AES library, there is just a problem using it using an instance of Cipher. If you have a specific piece of software that does not depend on JCA, you can for instance rewrite it to use the lightweight crypto API of Bouncy Castle.

    Note that many other parts of the Bouncy API themselves depend on the JCE. The lightweight API is also trickier to use and less documented/tested than the SunJCE.

    The Bouncy Castle lightweight API is pretty large as well. It contains a lot of functionality that you won't need. So it is probably too large for your applet. If it is I would advice you to create a new library that only contains the specific classes that you need from Bouncy Castle. The Bouncy Castle is fortunately very liberally licensed. As long as you keep the copyright statements etc. in place, you can easily split it off.

    0 讨论(0)
  • 2020-12-17 04:06

    EDIT: Here's an updated answer to this question: How to avoid installing "Unlimited Strength" JCE policy files when deploying an application?


    It is possible to disable the key size restrictions simply by using a few lines of reflection. We use this method in our program which needs access to 256-bit cryptography for interoperability purposes.

    private static void removeCryptographyRestrictions() {
        if (!isRestrictedCryptography()) {
            return;
        }
        try {
            java.lang.reflect.Field isRestricted;
            try {
                final Class<?> c = Class.forName("javax.crypto.JceSecurity");
                isRestricted = c.getDeclaredField("isRestricted");
            } catch (final ClassNotFoundException e) {
                try {
                    // Java 6 has obfuscated JCE classes
                    final Class<?> c = Class.forName("javax.crypto.SunJCE_b");
                    isRestricted = c.getDeclaredField("g");
                } catch (final ClassNotFoundException e2) {
                    throw e;
                }
            }
            isRestricted.setAccessible(true);
            isRestricted.set(null, false);
        } catch (final Throwable e) {
            logger.log(Level.WARNING,
                    "Failed to remove cryptography restrictions", e);
        }
    }
    
    private static boolean isRestrictedCryptography() {
        return "Java(TM) SE Runtime Environment"
                .equals(System.getProperty("java.runtime.name"));
    }
    

    However, our program is not an applet, and I am not sure whether applets have access to the reflection API.

    The question about legality also remains. There is a reason for that limit. Consult a lawyer if you are concerned.

    If possible, try to keep it to 128-bit keys. Even when taking Moore's law into consideration, breaking 128-bit AES would take billions upon billions of years. Longer keys offer no benefit in the real world – particularly when the keys are derived from passwords, which don't have anywhere near 256 bits of entropy anyway.

    0 讨论(0)
提交回复
热议问题