Skip to content

Instantly share code, notes, and snippets.

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

Embed
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 = PKCS5S2ParametersGenerator.new
generator.init(pass.to_java_bytes, salt.to_java_bytes, iter)
parameters = generator.generateDerivedMacParameters(keylen*8)
String.from_java_bytes(parameters.getKey())
end
def self.pbkdf2_hmac_sha1(pass, salt, iter, keylen)
digest = SHA1Digest.new
pbkdf2_hmac(pass, salt, iter, keylen, digest)
end
end
end
@daicoden

This comment has been minimized.

Copy link

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.