Class: Saml::Kit::Crypto::SimpleCipher

Inherits:
Object
  • Object
show all
Defined in:
lib/saml/kit/crypto/simple_cipher.rb

Constant Summary collapse

ALGORITHMS =
{
  'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' => 'DES-EDE3-CBC',
  'http://www.w3.org/2001/04/xmlenc#aes128-cbc' => 'AES-128-CBC',
  'http://www.w3.org/2001/04/xmlenc#aes192-cbc' => 'AES-192-CBC',
  'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => 'AES-256-CBC',
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm, private_key) ⇒ SimpleCipher

Returns a new instance of SimpleCipher.



12
13
14
15
# File 'lib/saml/kit/crypto/simple_cipher.rb', line 12

def initialize(algorithm, private_key)
  @algorithm = algorithm
  @private_key = private_key
end

Class Method Details

.matches?(algorithm) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/saml/kit/crypto/simple_cipher.rb', line 17

def self.matches?(algorithm)
  ALGORITHMS[algorithm]
end

Instance Method Details

#decrypt(cipher_text) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saml/kit/crypto/simple_cipher.rb', line 21

def decrypt(cipher_text)
  cipher = OpenSSL::Cipher.new(ALGORITHMS[@algorithm])
  cipher.decrypt
  iv = cipher_text[0..cipher.iv_len-1]
  data = cipher_text[cipher.iv_len..-1]
  #cipher.padding = 0
  cipher.key = @private_key
  cipher.iv = iv

  Saml::Kit.logger.debug ['-key', @private_key].inspect
  Saml::Kit.logger.debug ['-iv', iv].inspect

  cipher.update(data) + cipher.final
end