tinggEncryption 2.0.1
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 +7 -0
- data/lib/tinggEncryption.rb +53 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 32fbc32e2d1698e8baf14ced521cdc2fbdedbc61eb56a229d6a8ac33b6ffa704
|
4
|
+
data.tar.gz: 3e8d756aa9b7045b4d9dea1606f863b090b70f380b835c6cd4a2b90649e8ecbb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ba611737d0cad6fcdaddeb35462772b422ee122a2d47446607039f33228aa429dd21a985fbe8338dd699df09d5a357752a31927eae30e63f1da326347c9db44
|
7
|
+
data.tar.gz: 429dbd8dfef019bd08ee386c303105eef905e5d2bbc27a1865e9056ee53c8688eb047d1e5222891ec37b3861f2263e5a510788b23e8b373b4254774b24556b12
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @auther : samson mwangi
|
4
|
+
|
5
|
+
|
6
|
+
require 'openssl'
|
7
|
+
require 'digest'
|
8
|
+
require 'base64'
|
9
|
+
|
10
|
+
module TinggEncryption
|
11
|
+
# This is the Main class
|
12
|
+
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)
|
17
|
+
|
18
|
+
# Create a encoded key and secret
|
19
|
+
# We could also have just created a random key
|
20
|
+
# key = OpenSSL::Cipher::Cipher.new(alg).random_key
|
21
|
+
|
22
|
+
@encoded_key = Digest::SHA2.hexdigest(secret_key)[0..31]
|
23
|
+
# By default data is padded to the nearest 16 bytes block. To turn
|
24
|
+
# this off, you may use the :padding => false (or nil) option.
|
25
|
+
#
|
26
|
+
# In this mode however, the caller is required to pad the data. In
|
27
|
+
# the following example the message is exactly 16 bytes long, so no
|
28
|
+
# error aries.
|
29
|
+
@encoded_iv = Digest::SHA2.hexdigest(iv_key)[0..15]
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def encryption(raw_data)
|
34
|
+
# @type
|
35
|
+
raise 'Key Error' if @encoded_key.nil? || @encoded_key.size != 32
|
36
|
+
|
37
|
+
string = raw_data.to_s
|
38
|
+
|
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
|
44
|
+
|
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))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tinggEncryption
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "@Samson Mwangi"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: The best encryption class
|
14
|
+
email: samson.mwangi@cellulant.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tinggEncryption.rb
|
20
|
+
homepage: https://tingg.com
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.6
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Welcome to Tingg
|
43
|
+
test_files: []
|