lib/ccrypto/java/engines/scrypt_engine.rb in ccrypto-java-0.1.0 vs lib/ccrypto/java/engines/scrypt_engine.rb in ccrypto-java-0.2.0
- old
+ new
@@ -6,29 +6,38 @@
class ScryptEngine
include DataConversion
include TR::CondUtils
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").random_bytes(@config.salt)
+ @config.salt = ::Java::byte[16].new
+ java.security.SecureRandom.getInstance("NativePRNG").next_bytes(@config.salt)
end
end
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)
+ 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
+
+ private
+ def logger
+ Ccrypto::Java.logger(:scrypt_eng)
end
end
end
end