OpenSSL::PKey::RSAError: Neither PUB key nor PRIV key: not enough data on travis-ci

OpenSSL::PKey::RSAError: Neither PUB key nor PRIV key: not enough data on travis-ci

我正在使用 google/api_client library in ruby。我的代码在开发和本地测试中运行良好,但在 Travis-CI 上运行不佳。我将我的私钥存储为本地和 Travis 上的多行字符串。我的代码在这里失败:

require "google/api_client"

class GoogleCalendarAdapter
  def key
    OpenSSL::PKey::RSA.new(ENV["GOOGLE_P12_PEM"], "notasecret")  # line 27
  end
end

我已经通过 Travis-CI 网络控制台将 GOOGLE_P12_PEM 环境变量定义为:

"-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAK...\n... \n-----END RSA PRIVATE KEY-----\n"

这是我收到的错误:

Failure/Error: events = calendar.fetch_events(start_time, end_time)
 OpenSSL::PKey::RSAError:
   Neither PUB key nor PRIV key: not enough data
 # ./lib/google_calendar_adapter.rb:27:in `initialize'
 # ./lib/google_calendar_adapter.rb:27:in `new'
 # ./lib/google_calendar_adapter.rb:27:in `key'
 # ./lib/google_calendar_adapter.rb:36:in `oauth2_client'
 # ./lib/google_calendar_adapter.rb:49:in `google_api_client'
 # ./lib/google_calendar_adapter.rb:15:in `fetch_events'
 # ./spec/lib/google_calendar_adapter_spec.rb:18:in `block (3 levels) in <top (required)>'

欢迎就如何解决此问题提出任何建议。

我最终加密了我的 p12 文件,并在我的 .travis.yml 中提供了有关如何解密该文件的说明,如文件所述,here