What is the correct way to configure a spring TextEncryptor for use on Heroku

前端 未结 3 926
轻奢々
轻奢々 2020-12-16 22:14

I have a spring TextEncryptor defined like this



        
3条回答
  •  無奈伤痛
    2020-12-16 22:44

    You can also do the following. Though this seems to have stopped working on the latest builds of Java 8.

        Field field = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted");
        if (Boolean.TRUE.equals(field.get(null))) {
            if (Modifier.isFinal(field.getModifiers())) {
                Field modifiers = Field.class.getDeclaredField("modifiers");
                modifiers.setAccessible(true);
                modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
            }
            field.setAccessible(true);
            field.setBoolean(null, false); // isRestricted = false;
            field.setAccessible(false);
        }
        textEncryptor = Encryptors.text(key, salt);
    

提交回复
热议问题