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.
- checksums.yaml +4 -4
- data/lib/tinggEncryption.rb +24 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 268daf2798e233c8dd6c0c67acce6fbe814695f4a47de9252794b10f1d13d0f9
|
4
|
+
data.tar.gz: 2ad0913fc5c0f822e64d3f8904cb5fb0d7013d5311a0b6d3e1ee9608d2cfc3f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b8ecd46dbef33f2d2b7eba3f50dac5c1ff5ad3aeef596255e7846adbc05f07fad474c63d389212ed689c14fc11c7f98ad9cf1868e466621b239789d73c0228
|
7
|
+
data.tar.gz: 136f1d755d49b391ee634693d50df1cb70c3d835dddc55976d1275e841376e95d6b10abfc2df333bfa1b8c4255595293afe3f5536dcf6c32f630e1a5ac168e32
|
data/lib/tinggEncryption.rb
CHANGED
@@ -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
|
-
#
|
12
|
+
# @!parse
|
12
13
|
class Encryption
|
13
|
-
def initialize(
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
@
|
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
|
-
@
|
30
|
-
|
31
|
+
@iv_key = Digest::SHA2.hexdigest(iv_key)[0..15]
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
+
def encrypt(data)
|
35
|
+
key = @secret_key
|
36
|
+
iv_key = @iv_key
|
34
37
|
# @type
|
35
|
-
raise 'Key Error' if
|
36
|
-
|
37
|
-
string = raw_data.to_s
|
38
|
+
raise 'Key Error' if key.nil? && iv_key.nil?
|
38
39
|
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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.
|
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
|
11
|
+
date: 2020-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: This is the Cellulant Merchant Encryption class
|
14
14
|
email: samson.mwangi@cellulant.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|