reversible_cryptography 0.3.0 → 0.4.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: b62a2069be44c9cf86f98fd026a43cd2a3d8e6be
4
- data.tar.gz: 104d949e5d362e3808d8262be73bcf0fe52d76a5
3
+ metadata.gz: 0a1bc771be00aef60470442376155e0cec258ec1
4
+ data.tar.gz: 8c48415de0490c13fe08d360c51a63859d8d5753
5
5
  SHA512:
6
- metadata.gz: 0af90075535d26a280902c8c0ffb25b2d433abf5c1cf64b17c221a92bf489ae81dfc3f0652032f9ccbc3877dc5269afa5f4abe19837f78bcbeeb3d6700626581
7
- data.tar.gz: dff254aab06ef0ce53238e34c90c9c8860e56c46d3ed5f266a4366b4cf9e7fd5134bd7d1116a1fa284687890d7508f2f686325bb1042ec90f6bb55b42d66a300
6
+ metadata.gz: 05e39700d448039ad725609669d14e4fb45cf499023bf3353fb8fa31a58e37b1d174afd45879830f69317a83c70646135d72b36695acd5ca4032e1ede22773ea
7
+ data.tar.gz: d86f76c63aa4f308baa28b3e3459d59686d21fe010abe378992c59d312655648dc22da928bd5d8b472ce03a186cb0d647c69d1e79cc0cae1dd129c1e48fefcc8
data/README.md CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
23
23
  ```ruby
24
24
  encrypted_message = ReversibleCryptography::Message.encrypt("target_message", "password")
25
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"
26
+ ReversibleCryptography::Message.decrypt(encrypted_message, "password") == "target_message"
27
27
  # => true
28
28
  ```
29
29
 
@@ -34,8 +34,8 @@ Add `reversible_cryptography` command
34
34
  $ reversible_cryptography
35
35
 
36
36
  Commands:
37
- reversible_cryptography decrypt [TEXT] # Decrypt text
38
- reversible_cryptography encrypt [TEXT] # Encrypt text
37
+ reversible_cryptography decrypt [TEXT] # Decrypt text or file
38
+ reversible_cryptography encrypt [TEXT] # Encrypt text or file
39
39
  reversible_cryptography help [COMMAND] # Describe available commands or one specific command
40
40
  ```
41
41
 
@@ -47,6 +47,16 @@ Input password:
47
47
  md5:78e731027d8fd50ed642340b7c9a63b3:salt:252-235-72-88-180-7-195-229:aes-256-cfb:VH2JxqUU9Q==
48
48
  ```
49
49
 
50
+ ```shell
51
+ cat original.txt
52
+ this is secret!
53
+
54
+ reversible_cryptography encrypt --password=pass --src-file=original.txt --dst-file=encrypted.txt
55
+
56
+ cat encrypted.txt
57
+ md5:f5b013aca1b774be3d3b5f09f76e6cc8:salt:228-129-190-248-134-146-102-97:aes-256-cfb:u+lhtAdW6Re8br0qePqzig==
58
+ ```
59
+
50
60
  #### Decrypt sample
51
61
 
52
62
  ```shell
@@ -55,6 +65,16 @@ Input password:
55
65
  message
56
66
  ```
57
67
 
68
+ ```shell
69
+ cat encrypted.txt
70
+ md5:f5b013aca1b774be3d3b5f09f76e6cc8:salt:228-129-190-248-134-146-102-97:aes-256-cfb:u+lhtAdW6Re8br0qePqzig==
71
+
72
+ reversible_cryptography decrypt --password=pass --src-file=encrypted.txt --dst-file=decrypted.txt
73
+
74
+ cat decrypted.txt
75
+ this is secret!
76
+ ```
77
+
58
78
  ## Development
59
79
 
60
80
  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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require "bundler/setup"
2
+
3
3
  require 'reversible_cryptography/cli'
4
4
 
5
5
  ReversibleCryptography::CLI.start(ARGV)
@@ -3,24 +3,44 @@ require 'reversible_cryptography'
3
3
 
4
4
  module ReversibleCryptography
5
5
  class CLI < Thor
6
- desc "encrypt [TEXT]", "Encrypt text"
6
+ desc "encrypt [TEXT]", "Encrypt text or file"
7
7
  option :password, type: :string, aliases: [:p]
8
+ option :src_file, type: :string, aliases: [:s], banner: "PLAIN_TEXT_FILE"
9
+ option :dst_file, type: :string, aliases: [:d], banner: "ENCRYPTED_TEXT_FILE"
8
10
  def encrypt(plain_text=nil)
11
+ plain_text = File.read(options[:src_file]) if options[:src_file]
9
12
  plain_text ||= ask("Input text:")
10
13
  password = options[:password]
11
14
  password ||= ask("Input password:", echo: false).tap { puts }
12
15
 
13
- puts ReversibleCryptography::Message.encrypt(plain_text, password)
16
+ encrypted_text = ReversibleCryptography::Message.encrypt(plain_text, password)
17
+ if options[:dst_file]
18
+ File.open(options[:dst_file], "wb") do |f|
19
+ f.write(encrypted_text)
20
+ end
21
+ else
22
+ puts encrypted_text
23
+ end
14
24
  end
15
25
 
16
- desc "decrypt [TEXT]", "Decrypt text"
26
+ desc "decrypt [TEXT]", "Decrypt text or file"
17
27
  option :password, type: :string, aliases: [:p]
28
+ option :src_file, type: :string, aliases: [:s], banner: "ENCRYPTED_TEXT_FILE"
29
+ option :dst_file, type: :string, aliases: [:d], banner: "PLAIN_TEXT_FILE"
18
30
  def decrypt(encrypted_text=nil)
31
+ encrypted_text = File.read(options[:src_file]) if options[:src_file]
19
32
  encrypted_text ||= ask("Input text:")
20
33
  password = options[:password]
21
34
  password ||= ask("Input password:", echo: false).tap { puts }
22
35
 
23
- puts ReversibleCryptography::Message.decrypt(encrypted_text, password)
36
+ plain_text = ReversibleCryptography::Message.decrypt(encrypted_text, password)
37
+ if options[:dst_file]
38
+ File.open(options[:dst_file], "wb") do |f|
39
+ f.write(plain_text)
40
+ end
41
+ else
42
+ puts plain_text
43
+ end
24
44
  end
25
45
  end
26
46
  end
@@ -1,3 +1,3 @@
1
1
  module ReversibleCryptography
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reversible_cryptography
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takumi MIURA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor