Module: ClaimToken::Encryptor
- Defined in:
- lib/claim_token/encryptor.rb
Class Method Summary collapse
- .build_cipher ⇒ Object
- .cipher_type ⇒ Object
- .encode(raw_string) ⇒ Object
- .encrypt(message) ⇒ Object
- .encrypt_message_with_cipher(message, cipher) ⇒ Object
- .encryption_key ⇒ Object
Class Method Details
.build_cipher ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/claim_token/encryptor.rb', line 31 def build_cipher cipher = OpenSSL::Cipher::Cipher.new(cipher_type) cipher.encrypt cipher.key = encryption_key cipher.iv = iv = cipher.random_iv return [cipher, iv] end |
.cipher_type ⇒ Object
39 40 41 |
# File 'lib/claim_token/encryptor.rb', line 39 def cipher_type ClaimToken.configuration.cipher_type end |
.encode(raw_string) ⇒ Object
51 52 53 |
# File 'lib/claim_token/encryptor.rb', line 51 def encode raw_string Base64.urlsafe_encode64 raw_string end |
.encrypt(message) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/claim_token/encryptor.rb', line 11 def encrypt = JSON.dump() cipher, iv = build_cipher encrypted_data = , cipher encoded_encrypted_data = encode(encrypted_data) signature = ClaimToken::Signer.sign(encoded_encrypted_data) { "type" => "EncryptedMessage", "cipher" => cipher_type, "data" => encoded_encrypted_data, "iv" => encode(iv), "signature" => signature, } end |
.encrypt_message_with_cipher(message, cipher) ⇒ Object
47 48 49 |
# File 'lib/claim_token/encryptor.rb', line 47 def , cipher cipher.update(.encode("UTF-8")) + cipher.final end |
.encryption_key ⇒ Object
43 44 45 |
# File 'lib/claim_token/encryptor.rb', line 43 def encryption_key ClaimToken.configuration.shared_encryption_key end |