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 +4 -4
- data/lib/pad_utils/pad_security.rb +67 -0
- data/lib/pad_utils/version.rb +1 -1
- data/lib/pad_utils.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f20532eea9d248ad0a3a09a1f38fec0aee429e8a
|
4
|
+
data.tar.gz: eedd6b1ab92a02888509016854a7d1dede571f82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/pad_utils/version.rb
CHANGED
data/lib/pad_utils.rb
CHANGED
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.
|
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
|