ece 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/ece/ece.rb +4 -5
- data/lib/ece/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1792d0df2dfaebbd292e5bded75b3443bf77b759
|
4
|
+
data.tar.gz: 86503dc1ef68ca2086807fc1bd76ad286c5241e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd05ae640d123bbd41ee6655b22f214e9211576dd4215e946cd0f2ba7970240979b5903b361adc0b3ead077f50fb93beb8d391178e7aea1b105c8fca53eb6af7
|
7
|
+
data.tar.gz: 8708544d9a4711ab34b49adb4937d49084a2033c646665217a096061de824959209325aa0fdc1489d72cc68692e47d23119931ca970e4cee9cff91f6bba8e014
|
data/README.md
CHANGED
@@ -22,16 +22,20 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Encrypting:
|
26
|
+
|
27
|
+
```ruby
|
26
28
|
require 'ece'
|
27
29
|
|
28
30
|
key = Random.new.bytes(16)
|
29
31
|
salt = Random.new.bytes(16)
|
30
32
|
data = "Your very private data"
|
31
33
|
|
32
|
-
Ece.encrypt(data, key: key, salt: salt)
|
33
|
-
|
34
|
-
|
34
|
+
encrypted_data = Ece.encrypt(data, key: key, salt: salt)
|
35
|
+
```
|
36
|
+
Decrypting:
|
37
|
+
```ruby
|
38
|
+
Ece.decrypt(encrypted_data, key: key, salt: salt)
|
35
39
|
```
|
36
40
|
Data can be bytestring as well.
|
37
41
|
## Contributing
|
data/lib/ece/ece.rb
CHANGED
@@ -2,7 +2,6 @@ require 'openssl'
|
|
2
2
|
require 'hkdf'
|
3
3
|
require 'base64'
|
4
4
|
|
5
|
-
#fore testing purposes only
|
6
5
|
#TODO: variable padding
|
7
6
|
|
8
7
|
class Ece
|
@@ -48,7 +47,7 @@ class Ece
|
|
48
47
|
|
49
48
|
def self.encrypt(data, params)
|
50
49
|
key = extract_key(params)
|
51
|
-
rs = 4095 #
|
50
|
+
rs = 4095 #should be variable, but for now it's constant
|
52
51
|
result = ""
|
53
52
|
counter = 0
|
54
53
|
(0..data.length).step(rs) do |i|
|
@@ -65,9 +64,9 @@ class Ece
|
|
65
64
|
gcm.decrypt
|
66
65
|
gcm.key = params[:key]
|
67
66
|
gcm.iv = generate_nonce(params[:nonce], counter)
|
68
|
-
gcm.auth_tag = buffer[-
|
69
|
-
decrypted = gcm.update(buffer[0..-
|
70
|
-
#padding = decrypted[0]
|
67
|
+
gcm.auth_tag = buffer[-TAG_LENGTH..-1]
|
68
|
+
decrypted = gcm.update(buffer[0..-TAG_LENGTH-1]) + gcm.final
|
69
|
+
#padding = decrypted[0] -- this would be used once variable record-size is implemented
|
71
70
|
#padding_length = decrypted[0].unpack("C")
|
72
71
|
#raise Err unless padding = "\x00"*padding_length
|
73
72
|
decrypted[1..-1]
|
data/lib/ece/version.rb
CHANGED