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.
likely means a mess up in class-path -> BC .jars loaded from somewhere else.
JRuby-OpenSSL's packed BC (in 0.9.19 it is 1.55) has the needed
Base64
method - otherwise would fail to compile the Ruby extension bits in the first place.