pad_utils 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d06cdf7e6ae17bb0933487b04dd42d0ee6d6f3c
4
- data.tar.gz: 0f2c26a775307f41bb0f9e6f40f29f335b3d8bc1
3
+ metadata.gz: f20532eea9d248ad0a3a09a1f38fec0aee429e8a
4
+ data.tar.gz: eedd6b1ab92a02888509016854a7d1dede571f82
5
5
  SHA512:
6
- metadata.gz: 075b8781b98d9c7bb2d841edc9eeb81aab83785cb3ad2fd1da0c3d2690865ce48e6a4af9066d8d21a0748c80e3510e0ccd1223d175ff0c236f3e7680b006803a
7
- data.tar.gz: 795be186f08c54b49765d7e54b2cfca25ec0cda428843138bb7b706fa13b2b1a886d4da780a2c81ed74b66848e0ac60b131a9aee06d36dc2e7fa20108a5a49c1
6
+ metadata.gz: b1789c6831bf3fd7e3624b1edd77e1840a5e9a474fa6ab6439d6a7320ade187945a8f2b023ca0d1467be0c8e73702e503afcf3c9ce905f7f9d9cde8e0dd84fd8
7
+ data.tar.gz: d0c74437e400de8032969f035b9749e7e0e4e4acd40a55213b1d6219655c250e75b1d0b304d6f0bb38df3c5d33eedc4023e6d4bb47d94a70b148b76515e4aa48
@@ -0,0 +1,67 @@
1
+ require 'base64'
2
+ require 'uri'
3
+ require 'openssl'
4
+ require 'digest/sha1'
5
+
6
+ module PadUtils
7
+
8
+ # Encrypts a string.
9
+ #
10
+ # @param content [String] the content to encrypt
11
+ # @param key [String] the encryption key
12
+ # @return [String] the encrypted string
13
+ # @example
14
+ # PadUtils.encrypt("Hello", "s3cr3t") # => 'DKBJVYG69YsAWT%0A__1f346a8eeedc7'
15
+ def self.encrypt(content: "", key: "")
16
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
17
+ cipher.encrypt
18
+
19
+ iv = PadUtils.uuid.gsub("-", "")
20
+
21
+ key = Digest::SHA1.hexdigest(key)
22
+
23
+ cipher.key = key
24
+ cipher.iv = iv
25
+
26
+ encrypted = '' << cipher.update(content) << cipher.final
27
+
28
+ encrypted = Base64.encode64(encrypted)
29
+ encrypted = URI.escape(encrypted, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
30
+
31
+ encrypted = "#{encrypted}__#{iv}"
32
+
33
+ rescue
34
+ encrypted = "invalid"
35
+ end
36
+
37
+ # Decrypts a string.
38
+ #
39
+ # @param content [String] the encrypted string
40
+ # @param key [String] the encryption key
41
+ # @return [String] the decrypted string
42
+ # @example
43
+ # PadUtils.decrypt("DKBJVYG69YsAWT%0A__1f346a8eeedc7", "s3cr3t") # => 'Hello'
44
+ def self.decrypt(content: "", key: "")
45
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
46
+ cipher.decrypt
47
+
48
+ key = Digest::SHA1.hexdigest(key)
49
+
50
+ iv = content.split("__")[1]
51
+ content = content.split("*+*")[0]
52
+
53
+ cipher.key = key
54
+ cipher.iv = iv
55
+
56
+ content = URI.unescape(content)
57
+ content = Base64.decode64(content)
58
+
59
+ decrypted = '' << cipher.update(content) << cipher.final
60
+
61
+ decrypted
62
+
63
+ rescue
64
+ decrypted = "invalid"
65
+ end
66
+
67
+ end
@@ -1,4 +1,4 @@
1
1
  module PadUtils
2
2
  # PadUtils version number
3
- VERSION = "1.7.1"
3
+ VERSION = "1.8.0"
4
4
  end
data/lib/pad_utils.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "pad_utils/pad_menu"
7
7
  require_relative "pad_utils/pad_json"
8
8
  require_relative "pad_utils/pad_color"
9
9
  require_relative "pad_utils/pad_code"
10
+ require_relative "pad_utils/pad_security"
10
11
 
11
12
  # Main namespace for PadUtils.
12
13
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pad_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Schuele
@@ -51,6 +51,7 @@ files:
51
51
  - lib/pad_utils/pad_json.rb
52
52
  - lib/pad_utils/pad_logger.rb
53
53
  - lib/pad_utils/pad_menu.rb
54
+ - lib/pad_utils/pad_security.rb
54
55
  - lib/pad_utils/pad_text.rb
55
56
  - lib/pad_utils/pad_time.rb
56
57
  - lib/pad_utils/version.rb