crypt-api 0.0.3 → 0.1.1

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: b8ee36a144a18c50dc6105dc08880208f69f53e3
4
- data.tar.gz: 64319210f733d382f30b5d8c8d5d53964904afb6
3
+ metadata.gz: 16afcc376e8a74be01e30333d9cc108a0917e45d
4
+ data.tar.gz: f691efa6e64d0b2abb6a79cfe527b1667c353cb8
5
5
  SHA512:
6
- metadata.gz: edac270899560d21e091c31735f8dd51eddc010003fb2d945c9bf0599232aa910bf6c32a9822abee4a0320fab510a31eb8bbdb04a5a7db86facceab9198d2f22
7
- data.tar.gz: bde9ad422985a408409bbe3eb72c8ff9f06703a22e377d6b67afd7b35756668f2db24e04f176332a561f18423fc716c5e7bfadf806e3cf242fc38e6c5563bded
6
+ metadata.gz: eb90c717db330de71aa2156ab6112b72ba632401897aeaedfa73566bad3c2d56674a010eb8f1e4b7b000a02509e58c607e2a4d9218cfb00fd42e3fe1b408a9cc
7
+ data.tar.gz: 443616a621145f2f6f85d0600a8aaa3bcd2bfa45ef5ee1c2b538cdb3dd89c834894afb55b5b549dce2f7581addd8e2948fc7c4492da2aea0d9d9c603dcc725d7
data/README.md CHANGED
@@ -7,7 +7,7 @@ The gem sending an encrypted request to the specified address and decrypting of
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'crypt_api'
10
+ gem 'crypt-api'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -24,13 +24,23 @@ Or install it yourself as:
24
24
  include CryptApi
25
25
  ```
26
26
 
27
- ```ruby
28
- CryptApi::Main.send_encrypted_request(YOUR_URL_HERE , data: {param_1: "param1", param_2: "param2" })
29
- ```
27
+ Sending the encrypted data:
28
+
29
+ ```ruby
30
+ secret_data = { secret_param_1: "param1", secret_param_2: "param2" }
31
+ encrypted_response = CryptApi::Main.send_encrypted_request(YOUR_URL_HERE , data: secret_data, YOUR_KEY)
32
+ ```
33
+
34
+ Decrypting of the response:
35
+
36
+ ```ruby
37
+ CryptApi::Main.decrypt_response(encrypted_response, YOUR_KEY)
38
+ ```
39
+
30
40
 
31
41
  ## Contributing
32
42
 
33
- 1. Fork it ( https://github.com/alexmatskevich/crypt_api/fork )
43
+ 1. Fork it ( https://github.com/alexmatskevich/crypt-api/fork )
34
44
  2. Create your feature branch (`git checkout -b my-new-feature`)
35
45
  3. Commit your changes (`git commit -am 'Add some feature'`)
36
46
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'bitcode_api/version'
4
+ require 'crypt_api/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "crypt-api"
8
- spec.version = BitcodeApi::VERSION
8
+ spec.version = CryptApi::VERSION
9
9
  spec.authors = ["Alexey"]
10
10
  spec.email = ["41exmackevich@gmail.com"]
11
11
  spec.summary = %q{Api}
@@ -0,0 +1,75 @@
1
+ require "crypt_api/version"
2
+ require "net/http"
3
+ require 'base64'
4
+ require 'openssl'
5
+
6
+
7
+ module CryptApi
8
+
9
+ class Sender
10
+
11
+ def initialize(url)
12
+ @url = url
13
+ end
14
+
15
+ def post_data(data)
16
+ uri = URI(@url)
17
+ response = Net::HTTP.post_form(uri, data)
18
+ response.body
19
+ end
20
+
21
+ end
22
+
23
+ class EncryptFactory
24
+
25
+ def encrypt(data, key)
26
+ cipher = OpenSSL::Cipher::AES.new(128, :CBC)
27
+ cipher.encrypt
28
+ cipher.key = key
29
+
30
+ code = cipher.update(data) + cipher.final
31
+
32
+ base64_encode( code )
33
+ end
34
+
35
+ def decrypt( encrypted_data, key )
36
+ code = base64_decode( encrypted_data )
37
+
38
+ decipher = OpenSSL::Cipher::AES.new(128, :CBC)
39
+ decipher.decrypt
40
+ decipher.key = key
41
+
42
+ decipher.update(decode) + decipher.final
43
+ end
44
+
45
+ private
46
+
47
+ def base64_encode(code)
48
+ Base64.encode64(code)
49
+ end
50
+
51
+ def base64_decode(encrypted_data)
52
+ Base64.decode64(encrypted_data)
53
+ end
54
+
55
+
56
+ end
57
+
58
+
59
+ class Main
60
+
61
+ def self.send_encrypted_request(url ,data, secret_key)
62
+ encryptor = EncryptFactory.new
63
+ encrypted_data = encryptor.encrypt(data.to_s, secret_key)
64
+ Sender.new(url).post_data(data: encrypted_data)
65
+ end
66
+
67
+ def self.decrypt_response(encrypted_response, secret_key)
68
+ decryptor = EncryptFactory.new
69
+ decryptor.decrypt(encrypted_data, secret_key)
70
+ end
71
+
72
+ end
73
+
74
+
75
+ end
@@ -0,0 +1,3 @@
1
+ module CryptApi
2
+ VERSION = "0.1.1"
3
+ end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypt-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  description: The gem sending an encrypted request to the specified address and decrypting
@@ -46,14 +46,14 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
50
  - Gemfile
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
- - bitcode_api.gemspec
55
- - lib/bitcode_api.rb
56
- - lib/bitcode_api/version.rb
54
+ - crypt_api.gemspec
55
+ - lib/crypt_api.rb
56
+ - lib/crypt_api/version.rb
57
57
  homepage: ''
58
58
  licenses:
59
59
  - MIT
@@ -64,17 +64,17 @@ require_paths:
64
64
  - lib
65
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.4.2
77
+ rubygems_version: 2.4.5
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Api
@@ -1,53 +0,0 @@
1
- require "bitcode_api/version"
2
- require "net/http"
3
- require 'openssl'
4
-
5
-
6
- module CryptApi
7
-
8
- class Sender
9
-
10
- def initialize(url)
11
- @url = url
12
- end
13
-
14
- def post_data(data)
15
- uri = URI(@url)
16
- response = Net::HTTP.post_form(uri, data)
17
- response.body
18
- end
19
-
20
- end
21
-
22
- class EncryptFactory
23
-
24
- def encrypt(data)
25
- cipher = OpenSSL::Cipher::AES.new(128, :CBC)
26
- cipher.encrypt
27
- key = cipher.random_key
28
- iv = cipher.random_iv
29
-
30
- cipher.update(data) + cipher.final
31
- end
32
-
33
- def decrypt
34
- decipher = OpenSSL::Cipher::AES.new(128, :CBC)
35
- decipher.decrypt
36
- decipher.key = key
37
- decipher.iv = iv
38
-
39
- decipher.update(encrypted) + decipher.final
40
- end
41
-
42
- end
43
-
44
-
45
- class Main
46
- def self.send_encrypted_request(url ,data)
47
- encrypted_data = EncryptFactory.new.encrypt(data.to_s)
48
- Sender.new(url).post_data(data: encrypted_data)
49
- end
50
- end
51
-
52
-
53
- end
@@ -1,3 +0,0 @@
1
- module BitcodeApi
2
- VERSION = "0.0.3"
3
- end