tinggEncryption 2.0.1 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tinggEncryption.rb +24 -25
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32fbc32e2d1698e8baf14ced521cdc2fbdedbc61eb56a229d6a8ac33b6ffa704
4
- data.tar.gz: 3e8d756aa9b7045b4d9dea1606f863b090b70f380b835c6cd4a2b90649e8ecbb
3
+ metadata.gz: 268daf2798e233c8dd6c0c67acce6fbe814695f4a47de9252794b10f1d13d0f9
4
+ data.tar.gz: 2ad0913fc5c0f822e64d3f8904cb5fb0d7013d5311a0b6d3e1ee9608d2cfc3f9
5
5
  SHA512:
6
- metadata.gz: 5ba611737d0cad6fcdaddeb35462772b422ee122a2d47446607039f33228aa429dd21a985fbe8338dd699df09d5a357752a31927eae30e63f1da326347c9db44
7
- data.tar.gz: 429dbd8dfef019bd08ee386c303105eef905e5d2bbc27a1865e9056ee53c8688eb047d1e5222891ec37b3861f2263e5a510788b23e8b373b4254774b24556b12
6
+ metadata.gz: d0b8ecd46dbef33f2d2b7eba3f50dac5c1ff5ad3aeef596255e7846adbc05f07fad474c63d389212ed689c14fc11c7f98ad9cf1868e466621b239789d73c0228
7
+ data.tar.gz: 136f1d755d49b391ee634693d50df1cb70c3d835dddc55976d1275e841376e95d6b10abfc2df333bfa1b8c4255595293afe3f5536dcf6c32f630e1a5ac168e32
@@ -2,52 +2,51 @@
2
2
 
3
3
  # @auther : samson mwangi
4
4
 
5
-
6
5
  require 'openssl'
7
6
  require 'digest'
8
7
  require 'base64'
8
+ require 'net/http'
9
+ require 'json'
9
10
 
10
11
  module TinggEncryption
11
- # This is the Main class
12
+ # @!parse
12
13
  class Encryption
13
- def initialize(iv_key, secret_key)
14
- # We use the AES 256 bit cipher-block chaining symmetric encryption
15
- @algorithm = 'AES-256-CBC'
16
- raise 'Key Error' if secret_key.nil? || (secret_key.size >= 32)
14
+ def initialize(secret_key, iv_key)
15
+ if secret_key.nil? || (secret_key.size != 32) \
16
+ && iv_key.nil? || iv_key.nil? || iv_key.size != 16
17
+ raise 'Key Error'
18
+ end
17
19
 
20
+ @algorithm = 'AES-256-CBC'
18
21
  # Create a encoded key and secret
19
22
  # We could also have just created a random key
20
- # key = OpenSSL::Cipher::Cipher.new(alg).random_key
21
23
 
22
- @encoded_key = Digest::SHA2.hexdigest(secret_key)[0..31]
24
+ @secret_key = Digest::SHA2.hexdigest(secret_key)[0..31]
23
25
  # By default data is padded to the nearest 16 bytes block. To turn
24
26
  # this off, you may use the :padding => false (or nil) option.
25
27
  #
26
28
  # In this mode however, the caller is required to pad the data. In
27
29
  # the following example the message is exactly 16 bytes long, so no
28
30
  # error aries.
29
- @encoded_iv = Digest::SHA2.hexdigest(iv_key)[0..15]
30
-
31
+ @iv_key = Digest::SHA2.hexdigest(iv_key)[0..15]
31
32
  end
32
33
 
33
- def encryption(raw_data)
34
+ def encrypt(data)
35
+ key = @secret_key
36
+ iv_key = @iv_key
34
37
  # @type
35
- raise 'Key Error' if @encoded_key.nil? || @encoded_key.size != 32
36
-
37
- string = raw_data.to_s
38
+ raise 'Key Error' if key.nil? && iv_key.nil?
38
39
 
39
- # Now we do the actual setup of the cipher
40
- encryptor = OpenSSL::Cipher.new(@algorithm)
41
- encryptor.encrypt
42
- encryptor.key = @encoded_key
43
- encryptor.iv = @encoded_iv
40
+ # encryption_type
41
+ encryption = OpenSSL::Cipher.new(@algorithm)
42
+ encryption.encrypt
43
+ encryption.key = key
44
+ encryption.iv = iv_key
45
+ cypher = encryption.update(JSON(data))
46
+ cypher << encryption.final
44
47
 
45
- # Now we go ahead and encrypt our plain text.
46
- encryption = encryptor.update(string)
47
- encryption << encryptor.final
48
- Base64.urlsafe_encode64(Base64.urlsafe_encode64(encryption))
48
+ Base64.encode64(Base64.encode64(cypher))
49
49
  end
50
50
 
51
51
  end
52
-
53
- end
52
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinggEncryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@Samson Mwangi"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-04 00:00:00.000000000 Z
11
+ date: 2020-03-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: The best encryption class
13
+ description: This is the Cellulant Merchant Encryption class
14
14
  email: samson.mwangi@cellulant.com
15
15
  executables: []
16
16
  extensions: []