Class: Naoki::DataSecure

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/naoki/data_secure.rb

Constant Summary collapse

LIB_ICAPI_FILE =
`uname -m`.match(/x86_64/) ? 'libICAPI_64.so' : 'libICAPI_32.so'
I_T_Init_File =
0
I_E_OK =
0
I_T_Auth_Password =
0
I_T_Operation_Encrypt =
0
I_T_Operation_Decrypt =
1
DEFAULTS =
{
  :algorithm => 'AES/CBC/PKCS5Padding',
  :key_name => 'stg-new-test-key',
  :initialization_vector => '1234567890123456',
}
MAX_SAFENET_BLOCK_SIZE =
31000
MAX_OUTPUT_BLOCK_SIZE =
32000

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_to_use = :account_number, options = {}) ⇒ DataSecure

Returns a new instance of DataSecure.



73
74
75
76
77
78
79
80
# File 'lib/naoki/data_secure.rb', line 73

def initialize(key_to_use = :account_number, options={})
  @options = DEFAULTS.merge(options.symbolize_keys)
  #check { I_C_Initialize(I_T_Init_File, @options[:properties_file]) }
  @session_pointer = FFI::MemoryPointer.new :pointer
  check { I_C_OpenSession(@session_pointer, I_T_Auth_Password, @options[:username], @options[:password]) }
  @cipherspec_pointer = FFI::MemoryPointer.new :pointer
  check { I_C_CreateCipherSpec(@options[:algorithm], @options[:keys][key_to_use.to_s], @cipherspec_pointer) }
end

Class Method Details

.init(file) ⇒ Object



12
# File 'lib/naoki/data_secure.rb', line 12

def self.init(file); end

Instance Method Details

#closeObject



13
# File 'lib/naoki/data_secure.rb', line 13

def close; end

#decrypt_stream(input_io, output_io) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/naoki/data_secure.rb', line 25

def decrypt_stream(input, out)
  val = input.read(3)
  raise ArgumentError, "Invalid encrypted data (#{val})" if val != 'ENC'
  count = IO.copy_stream(input, out)
  [count + 3, count]
end

#encrypt_stream(input_io, output_io) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/naoki/data_secure.rb', line 15

def encrypt_stream(input, out)
  out.write("ENC")
  count = 0
  while block = input.read(4096)
    count += block.size
    out.write(block)
  end
  [count, count + 3]
end