Sha256: 312dbff2fab594f67b5b30b8858d71a729ef71b7ea1ed4b2810108b8b0d4c6d7
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
require_relative 'provider' module GcryptoJce module SecureRandom def generate(opts = { }) eng = opts[:type] || "SHA1PRNG" prov = GcryptoJce::Provider.handle_options(opts, nil) if prov.nil? sr = java.security.SecureRandom.getInstance(eng) else sr = java.security.SecureRandom.getInstance(eng, prov) end byteLen = opts[:byteLen] hexLen = opts[:hexLen] intLen = opts[:intLen] if not byteLen.nil? and byteLen.to_i > 0 b = Java::byte[byteLen].new sr.nextBytes(b) b elsif not hexLen.nil? and hexLen.to_i > 0 b = Java::byte[hexLen*2].new sr.nextBytes(b) String.from_java_bytes(org.bouncycastle.util.encoders.Hex.encode(b)) elsif not intLen.nil? and intLen.to_i > 0 sr.nextInt else b = Java::byte[32].new sr.nextBytes(b) b end end # end generate end # end SecureRandom class SecureRandomEngine extend SecureRandom end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gcrypto_jce-0.2 | lib/gcrypto_jce/secure_random.rb |
gcrypto_jce-0.1 | lib/gcrypto_jce/secure_random.rb |