Class: AadhaarAuth::Encrypter
- Inherits:
-
Object
- Object
- AadhaarAuth::Encrypter
- Defined in:
- lib/aadhaar_auth/encrypter.rb
Constant Summary collapse
- ENC_ALGO =
'AES-256-ECB'
Class Method Summary collapse
Instance Method Summary collapse
- #calculate_hmac(data) ⇒ Object
- #encrypt_using_session_key(data) ⇒ Object
- #encrypted_session_key ⇒ Object
- #public_cert ⇒ Object
- #session_key ⇒ Object
Class Method Details
.public_cert ⇒ Object
36 37 38 |
# File 'lib/aadhaar_auth/encrypter.rb', line 36 def public_cert @public_cert ||= OpenSSL::X509::Certificate.new(File.read(Config.public_certificate_path)) end |
Instance Method Details
#calculate_hmac(data) ⇒ Object
27 28 29 |
# File 'lib/aadhaar_auth/encrypter.rb', line 27 def calculate_hmac(data) Base64.encode64(encrypt_using_session_key(Digest::SHA256.digest(data))) end |
#encrypt_using_session_key(data) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/aadhaar_auth/encrypter.rb', line 20 def encrypt_using_session_key(data) aes = OpenSSL::Cipher.new(ENC_ALGO) aes.encrypt aes.key = session_key (aes.update(data) + aes.final) end |
#encrypted_session_key ⇒ Object
13 14 15 16 17 18 |
# File 'lib/aadhaar_auth/encrypter.rb', line 13 def encrypted_session_key @encrypted_session_key ||= begin public_key = public_cert.public_key Base64.encode64(public_key.public_encrypt(session_key)) end end |
#public_cert ⇒ Object
31 32 33 |
# File 'lib/aadhaar_auth/encrypter.rb', line 31 def public_cert self.class.public_cert end |
#session_key ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/aadhaar_auth/encrypter.rb', line 5 def session_key @session_key ||= begin aes = OpenSSL::Cipher.new(ENC_ALGO) aes.encrypt aes.random_key end end |