module PkernelJce::IoUtils

Public Class Methods

ensure_java_bytes(bin) click to toggle source

end file_to_memory_byte_array

# File lib/pkernel_jce/io_utils.rb, line 21
def IoUtils.ensure_java_bytes(bin)
  if not bin.java_kind_of?(Java::byte[])
    bin.to_java_bytes
  elsif bin.is_a?(String)
    bin = bin.to_java.getBytes
  else
    bin
  end
end
file_to_memory_byte_array(path) click to toggle source
# File lib/pkernel_jce/io_utils.rb, line 5
def IoUtils.file_to_memory_byte_array(path)
  if path.nil? or path.empty?
    raise PkernelJce::Error, "Given path '#{path}' to load to memory is nil or empty"
  else
    f = java.io.File.new(path)
    b = Java::byte[f.length].new
    dis = java.io.DataInputStream.new(java.io.FileInputStream.new(f))
    dis.readFully(b)
    dis.close

    b
  end
end
from_hex(str) click to toggle source
# File lib/pkernel_jce/io_utils.rb, line 37
def IoUtils.from_hex(str)
  org.bouncycastle.util.encoders.Hex.decode(str)
end
to_hex(bin) click to toggle source

end ensure_java_bytes

# File lib/pkernel_jce/io_utils.rb, line 33
def IoUtils.to_hex(bin)
  String.from_java_bytes(org.bouncycastle.util.encoders.Hex.encode(bin))
end