Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Heroku JRuby上带Rails4的OpenSSL::Cipher::Cipherror_Heroku_Openssl_Jruby_Ruby On Rails 4 - Fatal编程技术网

Heroku JRuby上带Rails4的OpenSSL::Cipher::Cipherror

Heroku JRuby上带Rails4的OpenSSL::Cipher::Cipherror,heroku,openssl,jruby,ruby-on-rails-4,Heroku,Openssl,Jruby,Ruby On Rails 4,默认情况下,Rails4使用加密的cookie会话存储。当应用程序尝试加密cookie时,会引发以下错误:OpenSSL::Cipher::cipherror:密钥大小非法:可能需要为您的JRE安装Java Cryptography Extension(JCE)Unlimited Strength辖区策略文件(stacktrace:) 如前所述,这可以通过降低加密级别或安装JCE来解决-第一个是我不想做的事情,第二个是在heroku上不可能(afaik)。heroku开发中心现在有这篇文章: 在

默认情况下,Rails4使用加密的cookie会话存储。当应用程序尝试加密cookie时,会引发以下错误:
OpenSSL::Cipher::cipherror:密钥大小非法:可能需要为您的JRE安装Java Cryptography Extension(JCE)Unlimited Strength辖区策略文件
(stacktrace:)


如前所述,这可以通过降低加密级别或安装JCE来解决-第一个是我不想做的事情,第二个是在heroku上不可能(afaik)。

heroku开发中心现在有这篇文章:

在某些情况下,需要将文件与JDK捆绑在一起,以便在运行时JVM中公开功能。例如,为了利用更强大的加密库,通常会将无限强度Java加密扩展(JCE)添加到JDK中。为了处理这种情况,Heroku将把应用程序指定的.jdk覆盖文件夹中的文件复制到jdk的目录结构中

以下是如何将JCE文件添加到应用程序:

  • 在应用程序的根目录中,创建一个
    .jdk overlay
    文件夹

  • 将JCE
    local\u policy.jar
    US\u export\u policy.jar
    复制到
    .jdk overlay/jre/lib/security/

  • 提交文件

    $git add.jdk overlay
    $git commit-m“自定义JCE文件”

  • 部署到Heroku

    $git推送heroku主机


  • 不确定它是否能在Heroku上运行,但在我本地的Jruby上运行

    创建config/initializers/unlimited_-strength_-cryptography.rb:

    if RUBY_PLATFORM == 'java' # Allows the application to work with other Rubies if not JRuby
      require 'java'
      java_import 'java.lang.ClassNotFoundException'
    
      begin
        security_class = java.lang.Class.for_name('javax.crypto.JceSecurity')
        restricted_field = security_class.get_declared_field('isRestricted')
        restricted_field.accessible = true
        restricted_field.set nil, false
      rescue ClassNotFoundException => e
        # Handle Mac Java, etc not having this configuration setting
        $stderr.print "Java told me: #{e}n"
      end
    end
    
    使用“方法”,这解决了我在生产中的问题,但在没有救援的情况下破坏了dev

    # config/initializers/unrestricted_crypto.rb
    begin # Enable 'restricted' cipher libraries on crippled systems
      prop = Java::JavaxCrypto::JceSecurity.get_declared_field 'isRestricted'
      prop.accessible = true
      prop.set nil, false
    rescue NameError
    end
    

    这是因为不同的javas有不同的flavas。。。我会让自己出去。

    也遇到了这个问题。你能想出什么办法吗?把这个问题看作well@Mark现在有一篇关于如何在heroku上修复JCE的文章-看看这个答案是否有用。@GregoryOstermayr现在有一篇关于如何在heroku上修复JCE的文章-看看这个答案是否有用。我在Mac Java上发现了一些ClassNotFound异常。要解决这个问题,可以像本文中那样使用begin/rescue/end:另外,如果gem文件中包含
    gem'jruby openssl'
    ,则可以跳过JCE的安装。