Class: DIDWW::Encrypt
- Inherits:
-
Object
- Object
- DIDWW::Encrypt
- Defined in:
- lib/didww/encrypt.rb
Overview
Allows to encrypt file on Ruby-side before uploading to ‘/v3/encrypted_files`.
Constant Summary collapse
- AES_ALGO =
[256, :CBC]
- AES_KEY_LEN =
32
- AES_IV_LEN =
16
- LABEL =
''
- SEPARATOR =
':::'
Instance Attribute Summary collapse
-
#encryption_fingerprint ⇒ Object
readonly
Returns the value of attribute encryption_fingerprint.
-
#public_keys ⇒ Object
readonly
Returns the value of attribute public_keys.
Class Method Summary collapse
Instance Method Summary collapse
-
#encrypt(binary) ⇒ String
Binary content of an encrypted file.
-
#initialize ⇒ Encrypt
constructor
A new instance of Encrypt.
-
#reset! ⇒ Object
Resets public keys and fingerprint.
Constructor Details
#initialize ⇒ Encrypt
Returns a new instance of Encrypt.
41 42 43 |
# File 'lib/didww/encrypt.rb', line 41 def initialize reset! end |
Instance Attribute Details
#encryption_fingerprint ⇒ Object (readonly)
Returns the value of attribute encryption_fingerprint.
39 40 41 |
# File 'lib/didww/encrypt.rb', line 39 def encryption_fingerprint @encryption_fingerprint end |
#public_keys ⇒ Object (readonly)
Returns the value of attribute public_keys.
39 40 41 |
# File 'lib/didww/encrypt.rb', line 39 def public_keys @public_keys end |
Class Method Details
.encrypt(binary) ⇒ String
34 35 36 |
# File 'lib/didww/encrypt.rb', line 34 def encrypt(binary) new.encrypt(binary) end |
Instance Method Details
#encrypt(binary) ⇒ String
Returns binary content of an encrypted file.
47 48 49 50 51 52 53 |
# File 'lib/didww/encrypt.rb', line 47 def encrypt(binary) aes_key, aes_iv, encrypted_aes = encrypt_aes(binary) aes_credentials = aes_key + aes_iv encrypted_rsa_a = encrypt_rsa_oaep(public_keys[0], aes_credentials) encrypted_rsa_b = encrypt_rsa_oaep(public_keys[1], aes_credentials) encrypted_rsa_a + encrypted_rsa_b + encrypted_aes end |
#reset! ⇒ Object
Resets public keys and fingerprint.
56 57 58 59 |
# File 'lib/didww/encrypt.rb', line 56 def reset! @public_keys = fetch_public_keys @encryption_fingerprint = calculate_fingerprint end |