rypt 0.1.0 → 0.2.0
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/rypt/sha512.rb +25 -0
- data/lib/rypt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0393c78c31027d52b6d6dc169c5f974cb6e59027
|
|
4
|
+
data.tar.gz: a8e338299bcf15d77a7280c148af443feb3daaa0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2862839c991dfc35c225a2cc381b3466d90775e36a66af6150fcd7bd71c9b64c2e19c21da13ea4df887b2d820c0a613253bfdde4c06467e5c54d55f87b75f08c
|
|
7
|
+
data.tar.gz: d2365501fe7ce786619b30eeeaa1e74ea480c570157cce6c09078b0ede8e8bc5e49fce7d387b5b3f1ac80f9495bb272da654e1aaf4074d9dbfdbc12461e9634e
|
data/lib/rypt/sha512.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'digest'
|
|
2
2
|
require 'base64'
|
|
3
|
+
require 'securerandom'
|
|
3
4
|
|
|
4
5
|
module Rypt
|
|
5
6
|
# Implements the standard crypt(3) call with SHA-512 and a salt.
|
|
@@ -9,6 +10,21 @@ module Rypt
|
|
|
9
10
|
# 3. Finalize the hash result by reordering the bytes and base-64 encoding them using a custom mapping scheme
|
|
10
11
|
# At the end we are going to take the result of #3 and spit it out concatenated with the seed as the final result.
|
|
11
12
|
class Sha512
|
|
13
|
+
def self.encrypt(plain)
|
|
14
|
+
self.new.encrypt(plain)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.compare(encrypted, plain)
|
|
18
|
+
encryptor = self.new
|
|
19
|
+
salt = encryptor.extract_salt(encrypted)
|
|
20
|
+
return false unless salt
|
|
21
|
+
encrypted == self.new.run(salt, plain)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def extract_salt(encrypted)
|
|
25
|
+
encrypted.split("$")[2]
|
|
26
|
+
end
|
|
27
|
+
|
|
12
28
|
def init_hash(salt, pass)
|
|
13
29
|
alt_sum = Digest::SHA2.new(512).digest(pass + salt + pass)
|
|
14
30
|
s_length = [salt.length, 16].min
|
|
@@ -75,5 +91,14 @@ module Rypt
|
|
|
75
91
|
|
|
76
92
|
"$6$" + salt_trunc + "$" + finalize_block(hash_val)
|
|
77
93
|
end
|
|
94
|
+
|
|
95
|
+
def encrypt(plain)
|
|
96
|
+
run(generate_salt, plain)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def generate_salt
|
|
100
|
+
SecureRandom.hex(8)
|
|
101
|
+
end
|
|
102
|
+
|
|
78
103
|
end
|
|
79
104
|
end
|
data/lib/rypt/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rypt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Trey Evans
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-06-
|
|
11
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|