Question: JRuby error loading private key with jruby-openssl in bouncycastle

Question

JRuby error loading private key with jruby-openssl in bouncycastle

Answers 0
Added at 2017-01-04 15:01
Tags
Question

I'm trying to sign emails sent by my application with an s/mime certificate. The application uses JRuby 1.7.26 and the newest version of the jruby-openssl gem. (Version 0.9.19). When I try to load my private key like this:

key_file = File.read(Rails.root.join('config', 'domain.key'))
private_key = OpenSSL::PKey::RSA.new(key_file)

I get this error:

Java::JavaLang::NoSuchMethodError: org.bouncycastle.util.encoders.Base64.encode([BII)[B
from org.jruby.ext.openssl.x509store.PEMInputOutput.writeEncoded(PEMInputOutput.java:1496)
...

If that works i would like to sign the emails like this:

data = "Test"
OpenSSL::PKCS7.write_smime(OpenSSL::PKCS7.sign(certificate, private_key, data, [], OpenSSL::PKCS7::DETACHED))

I googled a lot to find solutions for this error or how to sign emails with JRuby in general but I could not find anything helpful.

Thank you in advance for any help.

Answers
Source Show
◀ Wstecz