Class: Tem::OpenSSL::Key

Inherits:
Object
  • Object
show all
Includes:
TemTools
Defined in:
lib/openssl/key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TemTools

crypt_with_sec, crypting_sec, generate_key_on_tem, sign_with_sec, signing_sec

Constructor Details

#initialize(pub_key, priv_decrypt_sec, priv_encrypt_sec, priv_sign_sec) ⇒ Key

Returns a new instance of Key.



11
12
13
14
15
16
# File 'lib/openssl/key.rb', line 11

def initialize(pub_key, priv_decrypt_sec, priv_encrypt_sec, priv_sign_sec)
  @pub_key = pub_key
  @priv_decrypt_sec = priv_decrypt_sec
  @priv_encrypt_sec = priv_encrypt_sec
  @priv_sign_sec = priv_sign_sec
end

Instance Attribute Details

#pub_keyObject (readonly)

Returns the value of attribute pub_key.



9
10
11
# File 'lib/openssl/key.rb', line 9

def pub_key
  @pub_key
end

Class Method Details

.load_from_tkfile(file) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openssl/key.rb', line 44

def self.load_from_tkfile(file)
  ossl_pub_key = OpenSSL::PKey::RSA.new file
  pub_key = Tem::Key.new_from_ssl_key ossl_pub_key
  begin
    ds_ary, es_ary, ss_ary = *YAML.load(file)
    priv_decrypt_sec = Tem::SecPack.new_from_array ds_ary
    priv_encrypt_sec = Tem::SecPack.new_from_array es_ary      
    priv_sign_sec = Tem::SecPack.new_from_array ss_ary
  rescue
    priv_decrypt_sec = nil
    priv_encrypt_sec = nil
    priv_sign_sec = nil
  end
  self.new pub_key, priv_decrypt_sec, priv_encrypt_sec, priv_sign_sec
end

.new_tem_key(tem) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/openssl/key.rb', line 36

def self.new_tem_key(tem)
  keys = TemTools.generate_key_on_tem tem
  decrypt_sec = TemTools.crypting_sec keys[:privk], tem, :decrypt
  encrypt_sec = TemTools.crypting_sec keys[:privk], tem, :encrypt
  sign_sec = TemTools.signing_sec keys[:privk], tem
  self.new keys[:pubk], decrypt_sec, encrypt_sec, sign_sec
end

Instance Method Details

#privk_decrypt(data, tem) ⇒ Object



24
25
26
# File 'lib/openssl/key.rb', line 24

def privk_decrypt(data, tem)
  TemTools.crypt_with_sec data, @priv_decrypt_sec, tem
end

#privk_encrypt(data, tem) ⇒ Object



28
29
30
# File 'lib/openssl/key.rb', line 28

def privk_encrypt(data, tem)
  TemTools.crypt_with_sec data, @priv_encrypt_sec, tem
end

#privk_sign(data, tem) ⇒ Object



32
33
34
# File 'lib/openssl/key.rb', line 32

def privk_sign(data, tem)
  TemTools.sign_with_sec data, @priv_sign_sec, tem
end

#to_tkfileObject



18
19
20
21
22
# File 'lib/openssl/key.rb', line 18

def to_tkfile
  @pub_key.ssl_key.to_s + [@priv_decrypt_sec.to_array,
                           @priv_encrypt_sec.to_array,
                           @priv_sign_sec.to_array].to_yaml
end