Module: CcipherFactory::SymKeyCipher

Includes:
TR::CondUtils
Defined in:
lib/ccipher_factory/symkey_cipher/symkey_cipher.rb,
lib/ccipher_factory/symkey_cipher/symkey_decrypt.rb,
lib/ccipher_factory/symkey_cipher/symkey_encrypt.rb,
lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb,
lib/ccipher_factory/symkey_cipher/symkey_att_encrypt.rb

Defined Under Namespace

Modules: SymKeyAttDecrypt, SymKeyAttEncrypt, SymKeyDecrypt, SymKeyEncrypt Classes: SKCipher

Class Method Summary collapse

Class Method Details

.algo_default(algo) ⇒ Object

def self.iv_length(key, mode)

c = OpenSSL::Cipher.new(key_to_spec(key, mode))
c.random_iv.length

end



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ccipher_factory/symkey_cipher/symkey_cipher.rb', line 75

def SymKeyCipher.algo_default(algo)
  case algo
  when :aes
    # param 0: Algo name for spec
    # param 1: key size
    # param 2: default mdoe
    #["AES", 256, :gcm]
    Ccrypto::DirectCipherConfig.new({ algo: :aes, keysize: 256, mode: :gcm, padding: :pkcs5 })
  when :chacha20_poly1305, :chacha20
    Ccrypto::DirectCipherConfig.new({ algo: :chacha20, keysize: 256, mode: :poly1305 })
    #["chacha20-poly1305", 256]
  when :blowfish
    Ccrypto::DirectCipherConfig.new({ algo: :blowfish, keysize: 128, mode: :cfb, padding: :pkcs5 })
    #["bf", 128, :ofb]
  when :camellia
    Ccrypto::DirectCipherConfig.new({ algo: :camellia, keysize: 256, mode: :ctr, padding: :pkcs5 })
    #["camellia", 256, :ctr]
  when :aria
    Ccrypto::DirectCipherConfig.new({ algo: :aria, keysize: 256, mode: :gcm, padding: :pkcs5 })
    #["aria", 256, :gcm]
  else
    raise SymKeyCipherError, "Unknown algo '#{algo}' default"
  end
end

.att_decryptorObject



35
36
37
38
39
# File 'lib/ccipher_factory/symkey_cipher/symkey_cipher.rb', line 35

def self.att_decryptor
  c = SKCipher.new
  c.extend(SymKeyAttDecrypt)
  c
end

.att_encryptorObject



29
30
31
32
33
# File 'lib/ccipher_factory/symkey_cipher/symkey_cipher.rb', line 29

def self.att_encryptor
  c = SKCipher.new
  c.extend(SymKeyAttEncrypt)
  c
end

.decryptorObject



23
24
25
26
27
# File 'lib/ccipher_factory/symkey_cipher/symkey_cipher.rb', line 23

def self.decryptor
  dec = SKCipher.new
  dec.extend(SymKeyDecrypt)
  dec
end

.encryptorObject

class SymKeyCipherError < StandardError; end



17
18
19
20
21
# File 'lib/ccipher_factory/symkey_cipher/symkey_cipher.rb', line 17

def self.encryptor
  c = SKCipher.new
  c.extend(SymKeyEncrypt)
  c  
end