ruby_rncryptor 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_rncryptor.rb +11 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8438c4eba7e15993712ecd52b6671b9f9343fffd
|
4
|
+
data.tar.gz: 2a6c76d61042318ca6d3d16188bab17f8fa73e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d253d4bf9d27ac7d89fa04704e110c7bae4943614e741ed00baa7c7edb6d93ba5f5ca73ea0f4b5d663f9326cbfc1b66cf399eb738ac9eac820a7ddd1757d57d0
|
7
|
+
data.tar.gz: 93dfa2f51115c5bf61382513fc8ce3bbb3ef30f86f2e57d1df1feaf52dbb61a061063186c2ccdd6d020c0099be3f15de52733fd7ef4988f2cdf1b07535a938f0
|
data/lib/ruby_rncryptor.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RubyRNCryptor by Erik Wrenholt.
|
2
|
-
# Based on data format described by Rob Napier
|
3
|
-
# https://github.com/
|
2
|
+
# Based on data format described by Rob Napier
|
3
|
+
# https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md
|
4
4
|
# MIT License
|
5
5
|
|
6
6
|
require 'openssl'
|
@@ -19,9 +19,9 @@ class RubyRNCryptor
|
|
19
19
|
iv = data[18,16]
|
20
20
|
cipher_text = data[34,data.length-66]
|
21
21
|
hmac = data[data.length-32,32]
|
22
|
-
|
22
|
+
|
23
23
|
msg = version + options + encryption_salt + hmac_salt + iv + cipher_text
|
24
|
-
|
24
|
+
|
25
25
|
# Verify password is correct. First try with correct encoding
|
26
26
|
hmac_key = PKCS5.pbkdf2_hmac_sha1(password, hmac_salt, 10000, 32)
|
27
27
|
verified = eql_time_cmp([HMAC.hexdigest('sha256', hmac_key, msg)].pack('H*'), hmac)
|
@@ -32,11 +32,11 @@ class RubyRNCryptor
|
|
32
32
|
hmac_key = PKCS5.pbkdf2_hmac_sha1(password, hmac_salt, 10000, 32)
|
33
33
|
verified = eql_time_cmp([HMAC.hexdigest('sha256', hmac_key, msg)].pack('H*'), hmac)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
raise "Password may be incorrect, or the data has been corrupted. (HMAC could not be verified)" unless verified
|
37
|
-
|
37
|
+
|
38
38
|
# HMAC was verified, now decrypt it.
|
39
|
-
cipher = Cipher
|
39
|
+
cipher = Cipher.new('aes-256-cbc')
|
40
40
|
cipher.decrypt
|
41
41
|
cipher.iv = iv
|
42
42
|
cipher.key = PKCS5.pbkdf2_hmac_sha1(password, encryption_salt, 10000, 32)
|
@@ -47,7 +47,7 @@ class RubyRNCryptor
|
|
47
47
|
def self.encrypt(data, password, version = 3)
|
48
48
|
|
49
49
|
raise "RubyRNCryptor only encrypts version 2 or 3" unless (version == 2 || version == 3)
|
50
|
-
|
50
|
+
|
51
51
|
version = version.chr.to_s # Currently version 3
|
52
52
|
options = 1.chr.to_s # Uses password
|
53
53
|
encryption_salt = SecureRandom.random_bytes(8)
|
@@ -56,8 +56,8 @@ class RubyRNCryptor
|
|
56
56
|
cipher_text = data[34,data.length-66]
|
57
57
|
|
58
58
|
hmac_key = PKCS5.pbkdf2_hmac_sha1(password, hmac_salt, 10000, 32)
|
59
|
-
|
60
|
-
cipher = Cipher
|
59
|
+
|
60
|
+
cipher = Cipher.new('aes-256-cbc')
|
61
61
|
cipher.encrypt
|
62
62
|
cipher.iv = iv
|
63
63
|
cipher.key = PKCS5.pbkdf2_hmac_sha1(password, encryption_salt, 10000, 32)
|
@@ -75,7 +75,7 @@ class RubyRNCryptor
|
|
75
75
|
end
|
76
76
|
str.bytes.to_a[0...str.length].map {|c| c.chr}.join
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# From http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/PKCS5.html#module-OpenSSL::PKCS5-label-Important+Note+on+Checking+Passwords
|
80
80
|
def self.eql_time_cmp(a, b)
|
81
81
|
unless a.length == b.length
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_rncryptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Wrenholt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Encrypt and Decrypt the RNCryptor format.
|
14
14
|
email: erik@timestretch.com
|
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
39
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.0.14
|
40
|
+
rubygems_version: 2.0.14.1
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Encrypt and Decrypt the RNCryptor format
|