Skip to content

Instantly share code, notes, and snippets.

@milgner milgner/pkcs5.rb
Last active Dec 10, 2015

What would you like to do?
Basic PKCS5 support in JRuby
require 'java'
module OpenSSL
class PKCS5
java_import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator
java_import org.bouncycastle.crypto.digests.SHA1Digest
# it should probably support a non-bouncy-castle-digest as its 5th param, but nevermind
def self.pbkdf2_hmac(pass, salt, iter, keylen, digest)
generator =
generator.init(pass.to_java_bytes, salt.to_java_bytes, iter)
parameters = generator.generateDerivedMacParameters(keylen*8)
def self.pbkdf2_hmac_sha1(pass, salt, iter, keylen)
digest =
pbkdf2_hmac(pass, salt, iter, keylen, digest)

This comment has been minimized.

Copy link

daicoden commented Aug 1, 2013

Milgner - this really saved me thank you. Some tags to light the way.

jruby rails4 heroku jruby-1.7.1 uninitialized constant OpenSSL::PKCS5

had to add these two gems to the gemfile:

gem 'bouncy-castle-java'
gem 'jruby-openssl'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.