cryptrb 0.0.3
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 +7 -0
- data/lib/cryptrb.rb +15 -0
- data/lib/cryptrb/safe.rb +38 -0
- data/lib/cryptrb/version.rb +3 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b20b1085fc5209d3db6be98c3499a785d7235ff4ce03707020c7b1fa5456256b
|
4
|
+
data.tar.gz: 7eff6868a9880e518ec7cc72e78c9e93737b3e146a453acba0ea504bc5b62f48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d2d447fef20b42dc19f6a17455d8a7bc52125b7ff255a59cbd4dd001ebb1b10cb0d389ca5e69a8821e489066f2cde1049c9b8e01f2257a656d2868cec5e4cae
|
7
|
+
data.tar.gz: 3918bc6a5a525023ebfc4fa1ced28fc93fc83bc6dbdd61036929dc01a0c8c7a2dd438fdc6c895153d924f5ff1ad1d92f10aa91c46e9257218c93fec92ea52c25
|
data/lib/cryptrb.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './cryptrb/version.rb'
|
2
|
+
require_relative './cryptrb/safe.rb'
|
3
|
+
|
4
|
+
# safe = Symmetric::Safe.new
|
5
|
+
|
6
|
+
# safe.fill "toto"
|
7
|
+
# safe.close "titi"
|
8
|
+
|
9
|
+
# dumped_data = Base64.encode64 Marshal.dump(safe)
|
10
|
+
|
11
|
+
# safe_loaded = Marshal.load Base64.decode64(dumped_data)
|
12
|
+
|
13
|
+
# data = safe_loaded.open "titi"
|
14
|
+
|
15
|
+
# puts data
|
data/lib/cryptrb/safe.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Symmetric
|
4
|
+
class Safe
|
5
|
+
|
6
|
+
def fill(data)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def close(pwd)
|
11
|
+
cipher = OpenSSL::Cipher::AES256.new(:CBC)
|
12
|
+
cipher.encrypt
|
13
|
+
@iv = cipher.random_iv
|
14
|
+
|
15
|
+
@salt = OpenSSL::Random.random_bytes 16
|
16
|
+
@iter = 20000
|
17
|
+
key_len = cipher.key_len
|
18
|
+
digest = OpenSSL::Digest::SHA256.new
|
19
|
+
|
20
|
+
key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, @salt, @iter, key_len, digest)
|
21
|
+
cipher.key = key
|
22
|
+
@data = cipher.update(@data) + cipher.final
|
23
|
+
end
|
24
|
+
|
25
|
+
def open(pwd)
|
26
|
+
decipher = OpenSSL::Cipher::AES256.new(:CBC)
|
27
|
+
decipher.decrypt
|
28
|
+
decipher.iv = @iv
|
29
|
+
|
30
|
+
key_len = decipher.key_len
|
31
|
+
digest = OpenSSL::Digest::SHA256.new
|
32
|
+
|
33
|
+
key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, @salt, @iter, key_len, digest)
|
34
|
+
decipher.key = key
|
35
|
+
@data = decipher.update(@data) + decipher.final
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cryptrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guillaume Galas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem for cryptography
|
14
|
+
email: guillaume.galas@guivic.io
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/cryptrb.rb
|
20
|
+
- lib/cryptrb/safe.rb
|
21
|
+
- lib/cryptrb/version.rb
|
22
|
+
homepage: http://rubygems.org/gems/cryptrb
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.7.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A simple gem for cryptography
|
46
|
+
test_files: []
|