Class: SecurityClient::Algo
- Inherits:
-
Object
- Object
- SecurityClient::Algo
- Defined in:
- lib/security_client.rb
Instance Method Summary collapse
- #decryptor(obj, key, iv) ⇒ Object
- #encryptor(obj, key, iv = nil) ⇒ Object
- #get_algo(name) ⇒ Object
- #set_algo ⇒ Object
Instance Method Details
#decryptor(obj, key, iv) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/security_client.rb', line 245 def decryptor(obj, key, iv) cipher = obj[:mode] raise RuntimeError, 'Invalid key length' if key.length != obj[:key_length] raise RuntimeError, 'Invalid initialization vector length' if (iv!= nil and iv.length != obj[:iv_length]) cipher = obj[:mode] cipher.decrypt cipher.key = key cipher.iv = iv return cipher end |
#encryptor(obj, key, iv = nil) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/security_client.rb', line 229 def encryptor(obj,key, iv=nil) # key : A byte string containing the key to be used with this encryption # If the caller specifies the initialization vector, it must be # the correct length and, if so, will be used. If it is not # specified, the function will generate a new one cipher = obj[:mode] raise RuntimeError, 'Invalid key length' if key.length != obj[:key_length] raise RuntimeError, 'Invalid initialization vector length' if (iv!= nil and iv.length != obj[:iv_length]) cipher.encrypt cipher.key = key iv = cipher.random_iv return cipher, iv end |
#get_algo(name) ⇒ Object
225 226 227 |
# File 'lib/security_client.rb', line 225 def get_algo(name) set_algo[name] end |
#set_algo ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/security_client.rb', line 212 def set_algo @algorithm = { "aes-256-gcm"=>{ id:0, algorithm: OpenSSL::Cipher::AES256, mode: OpenSSL::Cipher::AES256.new(:GCM), key_length: 32, iv_length: 12, tag_length: 16 }, } end |