rypt 0.1.0 → 0.2.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: 8f7c7e6578e7ed82c0cb83ceecc831fde58389e3
4
- data.tar.gz: a1a919ef3158eddde0dc1a750ce462d9b89ff85f
3
+ metadata.gz: 0393c78c31027d52b6d6dc169c5f974cb6e59027
4
+ data.tar.gz: a8e338299bcf15d77a7280c148af443feb3daaa0
5
5
  SHA512:
6
- metadata.gz: cb60404071678964452f847347e6dc4959627efb3247f81caf92b233979604889b5276d8644c74b3cc1e8b618b8282cbb523a8a57f01d2494964bb5bc61df966
7
- data.tar.gz: c5b59bf1a2ac1d70d3233a9ebd24281dc983415302de8ea737c99c7db3e74f7d905531ab329ff8396ee138186ed573e5dc286737310c87c6199779884f63f1f2
6
+ metadata.gz: 2862839c991dfc35c225a2cc381b3466d90775e36a66af6150fcd7bd71c9b64c2e19c21da13ea4df887b2d820c0a613253bfdde4c06467e5c54d55f87b75f08c
7
+ data.tar.gz: d2365501fe7ce786619b30eeeaa1e74ea480c570157cce6c09078b0ede8e8bc5e49fce7d387b5b3f1ac80f9495bb272da654e1aaf4074d9dbfdbc12461e9634e
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rypt
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-23 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler