Class: Ccrypto::Java::ScryptEngine
- Inherits:
-
Object
- Object
- Ccrypto::Java::ScryptEngine
- Includes:
- DataConversion, TR::CondUtils
- Defined in:
- lib/ccrypto/java/engines/scrypt_engine.rb
Instance Method Summary collapse
- #derive(input, output = :binary) ⇒ Object
-
#initialize(conf, &block) ⇒ ScryptEngine
constructor
A new instance of ScryptEngine.
Methods included from DataConversion
#from_b64, #from_b64_mime, #from_hex, included, #to_b64, #to_b64_mime, #to_bin, #to_hex, #to_java_bytes, #to_str
Constructor Details
#initialize(conf, &block) ⇒ ScryptEngine
Returns a new instance of ScryptEngine.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ccrypto/java/engines/scrypt_engine.rb', line 10 def initialize(conf, &block) raise KDFEngineException, "KDF config is expected" if not conf.is_a?(Ccrypto::KDFConfig) raise KDFEngineException, "Output bit length (outBitLength) value is not given or not a positive value (#{conf.outBitLength})" if is_empty?(conf.outBitLength) or conf.outBitLength <= 0 @config = conf if is_empty?(@config.salt) @config.salt = ::Java::byte[16].new java.security.SecureRandom.getInstance("NativePRNG").next_bytes(@config.salt) end end |
Instance Method Details
#derive(input, output = :binary) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ccrypto/java/engines/scrypt_engine.rb', line 22 def derive(input, output = :binary) res = org.bouncycastle.crypto.generators.SCrypt.generate(to_java_bytes(input), to_java_bytes(@config.salt),@config.cost, @config.blocksize, @config.parallel, @config.outBitLength/8) #logger.debug "scrypt output : #{res.inspect}" case output when :hex to_hex(res) when :b64 to_b64(res) else res end end |