reversible_cryptography 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/reversible_cryptography.rb +6 -0
- data/lib/reversible_cryptography/message.rb +61 -0
- data/lib/reversible_cryptography/version.rb +3 -0
- data/reversible_cryptography.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4a880a0b830354528b288c488944d6bd294eb28
|
4
|
+
data.tar.gz: 3a605628d19a4883eeb677ecb845b72844157587
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 066c4f2bebed3fabf0ad9b1a1fc8b426d3f6342def145e298bee543002be280b9a48192f73ad485cf7a008bbcba3f6946ac75386f1b9498e0d4840cb1b59ce55
|
7
|
+
data.tar.gz: de6354f2f52bb1f012e5831c953435cf4401b06f8f036472947be8264f4ea6cb750ffba2cbf9528272e9f2925b2c64891071aff52c41effad850fc8edcea6c2d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# ReversibleCryptography
|
2
|
+
|
3
|
+
Easy-to-use reversible encryption solutions.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'reversible_cryptography'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install reversible_cryptography
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
encrypted_message = ReversibleCryptography::Message.encrypt("target_message", "password")
|
25
|
+
# => "md5:388eeae24576572f946e9043a2118b2d:salt:161-225-182-109-143-90-1-28:aes-256-cfb:DHY6DF3+iFzH36FMbeI="
|
26
|
+
ReversibleCryptography::Message.encrypt(encrypted_message, "password") == "target_message"
|
27
|
+
# => true
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( https://github.com/mitaku/reversible_cryptography/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "reversible_cryptography"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
module ReversibleCryptography
|
5
|
+
class Message
|
6
|
+
MODE = "CFB"
|
7
|
+
PREFIX = "aes-256-cfb"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def encrypt(str, password)
|
11
|
+
enc = OpenSSL::Cipher::AES256.new(MODE)
|
12
|
+
enc.encrypt
|
13
|
+
|
14
|
+
salt = OpenSSL::Random.random_bytes(8)
|
15
|
+
salt_string = generate_salt_string(salt)
|
16
|
+
|
17
|
+
set_key_and_iv(enc, password, salt)
|
18
|
+
|
19
|
+
result = enc.update(str) + enc.final
|
20
|
+
|
21
|
+
md5 = OpenSSL::Digest.hexdigest("MD5", str)
|
22
|
+
["md5", md5, "salt", salt_string, PREFIX, Base64.encode64(result).chomp].join(":")
|
23
|
+
end
|
24
|
+
|
25
|
+
def decrypt(str, password)
|
26
|
+
key = str.sub(/^md5:(.+):salt:(.+):#{PREFIX}:/, '')
|
27
|
+
md5 = $1
|
28
|
+
salt_string = $2
|
29
|
+
|
30
|
+
salt = convert_salt(salt_string)
|
31
|
+
|
32
|
+
dec = OpenSSL::Cipher::AES256.new(MODE)
|
33
|
+
dec.decrypt
|
34
|
+
set_key_and_iv(dec, password, salt)
|
35
|
+
|
36
|
+
result = dec.update(Base64.decode64(key)) + dec.final
|
37
|
+
if OpenSSL::Digest.hexdigest("MD5", result) == md5
|
38
|
+
result
|
39
|
+
else
|
40
|
+
raise StandardError.new("Invalid Password")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def set_key_and_iv(cipher, password, salt)
|
47
|
+
key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password, salt, 2000, cipher.key_len + cipher.iv_len)
|
48
|
+
cipher.key = key_iv[0, cipher.key_len]
|
49
|
+
cipher.iv = key_iv[cipher.key_len, cipher.iv_len]
|
50
|
+
end
|
51
|
+
|
52
|
+
def convert_salt(str)
|
53
|
+
str.split("-").map(&:to_i).pack("C*")
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_salt_string(salt)
|
57
|
+
salt.unpack("C*").join("-")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reversible_cryptography/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "reversible_cryptography"
|
8
|
+
spec.version = ReversibleCryptography::VERSION
|
9
|
+
spec.authors = ["Takumi MIURA"]
|
10
|
+
spec.email = ["mitaku1104@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Símplifìed reversible encryption solution}
|
13
|
+
spec.description = %q{A Símplifìed reversible encryption solution}
|
14
|
+
spec.homepage = "https://github.com/mitaku/reversible_cryptography"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reversible_cryptography
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takumi MIURA
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A Símplifìed reversible encryption solution
|
56
|
+
email:
|
57
|
+
- mitaku1104@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/reversible_cryptography.rb
|
71
|
+
- lib/reversible_cryptography/message.rb
|
72
|
+
- lib/reversible_cryptography/version.rb
|
73
|
+
- reversible_cryptography.gemspec
|
74
|
+
homepage: https://github.com/mitaku/reversible_cryptography
|
75
|
+
licenses: []
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A Símplifìed reversible encryption solution
|
97
|
+
test_files: []
|