crypto_yellowme 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +58 -0
- data/MIT-LICENSE +20 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/crypto.gemspec +27 -0
- data/lib/crypto.rb +18 -0
- data/lib/crypto/commons.rb +64 -0
- data/lib/crypto/config.rb +11 -0
- data/lib/crypto/encryptor.rb +15 -0
- data/lib/crypto/rsa_key.rb +61 -0
- data/lib/crypto/version.rb +3 -0
- data/spec/crypto/commons_spec.rb +104 -0
- data/spec/crypto/encryptor_spec.rb +26 -0
- data/spec/crypto/rsa_key_spec.rb +50 -0
- data/spec/spec_helper.rb +8 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cff08bb6b3a56e1f32236ef0734089eb368c7e2c3a42e93e9c79829e81b23a82
|
4
|
+
data.tar.gz: 042a61283983d9ecec91c52e31e358e02521d532d7f68dfeaf6de5a9199064b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bea3e1acb9f4edada03cc8c03ee9d77d1c04223aefaa342b09db99bcacab8566169d790bce73cd827a447e6c5941324d67be391d16bbbf0ce40b0e82aa2fb5f
|
7
|
+
data.tar.gz: 14ef7d7e9c2c30197450f576642ff8f47f742b8866ef5199bbcf91136f598b26dd5a475a5672206769078593ac49aa94b14e9a3d6c3e2e4ff5f9a1f80ea12e91
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
.DS_Store
|
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
# Declare your gem's dependencies in commons.gemspec.
|
5
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
6
|
+
# development dependencies will be added by default to the :development group.
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
# Declare any dependencies that are still in development here instead of in
|
10
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
11
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
12
|
+
# your gem to rubygems.org.
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
crypto_yellowme (0.3.0)
|
5
|
+
activemodel (~> 5.2.0)
|
6
|
+
activesupport (~> 5.0)
|
7
|
+
bcrypt (~> 3.1.7)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (5.2.4.1)
|
13
|
+
activesupport (= 5.2.4.1)
|
14
|
+
activesupport (5.2.4.1)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
bcrypt (3.1.13)
|
20
|
+
concurrent-ruby (1.1.5)
|
21
|
+
diff-lcs (1.3)
|
22
|
+
docile (1.3.2)
|
23
|
+
i18n (1.7.0)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
json (2.2.0)
|
26
|
+
minitest (5.13.0)
|
27
|
+
rspec (3.8.0)
|
28
|
+
rspec-core (~> 3.8.0)
|
29
|
+
rspec-expectations (~> 3.8.0)
|
30
|
+
rspec-mocks (~> 3.8.0)
|
31
|
+
rspec-core (3.8.2)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-expectations (3.8.4)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-mocks (3.8.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-support (3.8.2)
|
40
|
+
simplecov (0.17.0)
|
41
|
+
docile (~> 1.1)
|
42
|
+
json (>= 1.8, < 3)
|
43
|
+
simplecov-html (~> 0.10.0)
|
44
|
+
simplecov-html (0.10.2)
|
45
|
+
thread_safe (0.3.6)
|
46
|
+
tzinfo (1.2.6)
|
47
|
+
thread_safe (~> 0.1)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
crypto_yellowme!
|
54
|
+
rspec
|
55
|
+
simplecov
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
1.17.2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Juan Ku
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/crypto.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "crypto/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "crypto_yellowme"
|
9
|
+
spec.version = Crypto::VERSION
|
10
|
+
spec.date = '2019-12-10'
|
11
|
+
spec.summary = "Crypto is Yellowme's lib for crypto & security"
|
12
|
+
spec.description = "Crypto is Yellowme's ruby crypto & security utilities gem"
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
spec.authors = ["Yellowme"]
|
17
|
+
spec.email = 'hola@yellowme.mx'
|
18
|
+
spec.homepage = 'https://github.com/yellowme/crypto-ruby'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.add_dependency "bcrypt", "~> 3.1.7"
|
22
|
+
spec.add_dependency 'activesupport', '~> 5.0'
|
23
|
+
spec.add_dependency "activemodel", "~> 5.2"
|
24
|
+
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.17"
|
27
|
+
end
|
data/lib/crypto.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'crypto/config'
|
2
|
+
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'active_support/message_encryptor'
|
5
|
+
require 'active_support/key_generator'
|
6
|
+
require 'active_support/concern'
|
7
|
+
require 'active_model/secure_password'
|
8
|
+
require 'securerandom'
|
9
|
+
require 'bcrypt'
|
10
|
+
require 'openssl'
|
11
|
+
require 'open3'
|
12
|
+
|
13
|
+
require 'crypto/commons'
|
14
|
+
require 'crypto/encryptor'
|
15
|
+
require 'crypto/rsa_key'
|
16
|
+
|
17
|
+
module Crypto
|
18
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Crypto
|
2
|
+
class Commons
|
3
|
+
SALT_SPLITTER = '$$'.freeze
|
4
|
+
|
5
|
+
def self.encrypt(text, secret = Crypto.secret_key_base.to_s, cipher: 'aes-256-gcm')
|
6
|
+
text = text.to_s unless text.is_a? String
|
7
|
+
|
8
|
+
len = ActiveSupport::MessageEncryptor.key_len(cipher)
|
9
|
+
salt = SecureRandom.hex len
|
10
|
+
key = ActiveSupport::KeyGenerator.new(secret)
|
11
|
+
.generate_key salt, len
|
12
|
+
crypt = ActiveSupport::MessageEncryptor.new(key, cipher: cipher)
|
13
|
+
encrypted_data = crypt.encrypt_and_sign text
|
14
|
+
"#{salt}#{SALT_SPLITTER}#{encrypted_data}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.decrypt(text, secret = Crypto.secret_key_base.to_s, cipher: 'aes-256-gcm')
|
18
|
+
salt, data = text.split SALT_SPLITTER
|
19
|
+
|
20
|
+
len = ActiveSupport::MessageEncryptor.key_len(cipher)
|
21
|
+
key = ActiveSupport::KeyGenerator.new(secret)
|
22
|
+
.generate_key salt, len
|
23
|
+
crypt = ActiveSupport::MessageEncryptor.new(key, cipher: cipher)
|
24
|
+
crypt.decrypt_and_verify data
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.hash(text)
|
28
|
+
text = text.to_s unless text.is_a? String
|
29
|
+
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
|
30
|
+
BCrypt::Engine.cost
|
31
|
+
BCrypt::Password.create(text, cost: cost)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.hash_compare(hash, text)
|
35
|
+
password = BCrypt::Password.new(hash)
|
36
|
+
password == text
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.md5_digest(text)
|
40
|
+
text = text.to_s unless text.is_a? String
|
41
|
+
Digest::MD5.hexdigest(text)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.checksum(text)
|
45
|
+
text = text.to_s unless text.is_a? String
|
46
|
+
Digest::SHA2.new(256).hexdigest(text)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.checksum512(text)
|
50
|
+
text = text.to_s unless text.is_a? String
|
51
|
+
Digest::SHA2.new(512).hexdigest(text)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.sha256(secret_key, text)
|
55
|
+
OpenSSL::HMAC.hexdigest('sha256', secret_key, text)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.rsa_seal(private_key, passphrase, text)
|
59
|
+
text = text.to_s unless text.is_a? String
|
60
|
+
key = Crypto::RSAKey.new private_key, passphrase
|
61
|
+
key.seal(text)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Crypto
|
2
|
+
class Encryptor
|
3
|
+
def self.encrypt(options, secret=Crypto.secret_key_base.to_s)
|
4
|
+
return options[:value] if options[:value].blank?
|
5
|
+
|
6
|
+
Crypto::Commons.encrypt(options[:value], secret)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.decrypt(options, secret=Crypto.secret_key_base.to_s)
|
10
|
+
return options[:value] if options[:value].blank?
|
11
|
+
|
12
|
+
Crypto::Commons.decrypt(options[:value], secret)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Crypto
|
2
|
+
#
|
3
|
+
# Clase para crear llaves privadas, en formato X509 no PKCS7
|
4
|
+
#
|
5
|
+
# Para convertirlos vía linea de comandos:
|
6
|
+
# openssl pkcs8 -inform DER -in nombreGiganteDelSAT.key -passin pass:miFIELCreo >> certX509.pem
|
7
|
+
#
|
8
|
+
class RSAKey < OpenSSL::PKey::RSA
|
9
|
+
# path de la llave
|
10
|
+
attr_reader :path
|
11
|
+
|
12
|
+
# path de la llave .pem.enc
|
13
|
+
attr_reader :enc_path
|
14
|
+
|
15
|
+
# contraseña de la llave
|
16
|
+
attr_reader :password
|
17
|
+
|
18
|
+
# información de la llave en formato .pem
|
19
|
+
attr_reader :pem
|
20
|
+
|
21
|
+
# información de la llave en formato .pem.enc
|
22
|
+
attr_reader :enc_pem
|
23
|
+
attr_reader :data
|
24
|
+
|
25
|
+
#
|
26
|
+
# Crea una llave privada
|
27
|
+
#
|
28
|
+
# @param file [IO, String] El 'path' de esta llave o los bytes de la misma
|
29
|
+
# @param password [String, nil] El password de esta llave
|
30
|
+
#
|
31
|
+
# @return [Security::RSAKey] La llave privada
|
32
|
+
#
|
33
|
+
def initialize(file, password = nil)
|
34
|
+
@password = password
|
35
|
+
if File.file?(file)
|
36
|
+
@path = file
|
37
|
+
@enc_path = @path + '.enc'
|
38
|
+
file = File.read(@path)
|
39
|
+
end
|
40
|
+
super file, password
|
41
|
+
@data = to_s.gsub(/^-.+/, '').delete("\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Sella una cadena de texto
|
46
|
+
#
|
47
|
+
# @param original_chain [String] La cadena a firmar
|
48
|
+
#
|
49
|
+
# @return La cadena firmada
|
50
|
+
#
|
51
|
+
def seal(text)
|
52
|
+
Base64.encode64(sign(OpenSSL::Digest::SHA256.new, text)).delete("\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
# Encripta el pem generado, requerido para cancelar facturas
|
56
|
+
def encrypt_pem(encrypt_password)
|
57
|
+
cipher = OpenSSL::Cipher::Cipher.new('des3')
|
58
|
+
return to_pem(cipher, encrypt_password)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Crypto::Commons' do
|
4
|
+
let(:value) { '19999552059' }
|
5
|
+
|
6
|
+
describe 'encrypt working ok' do
|
7
|
+
subject do
|
8
|
+
Crypto::Commons.encrypt(value, 'secret')
|
9
|
+
end
|
10
|
+
|
11
|
+
it { expect { subject }.not_to raise_error }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'encrypt working ok without secret' do
|
15
|
+
subject do
|
16
|
+
Crypto::Commons.encrypt(value, 'secret')
|
17
|
+
end
|
18
|
+
|
19
|
+
it { expect { subject }.not_to raise_error }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'decrypt working ok' do
|
23
|
+
before do
|
24
|
+
@encrypted_value = Crypto::Commons.encrypt(value)
|
25
|
+
end
|
26
|
+
|
27
|
+
subject do
|
28
|
+
Crypto::Commons.decrypt(@encrypted_value)
|
29
|
+
end
|
30
|
+
|
31
|
+
it { expect { subject }.not_to raise_error }
|
32
|
+
it { expect(subject).to eq value }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'decrypt working ok without secret' do
|
36
|
+
before do
|
37
|
+
@encrypted_value = Crypto::Commons.encrypt(value)
|
38
|
+
end
|
39
|
+
|
40
|
+
subject do
|
41
|
+
Crypto::Commons.decrypt(@encrypted_value)
|
42
|
+
end
|
43
|
+
|
44
|
+
it { expect { subject }.not_to raise_error }
|
45
|
+
it { expect(subject).to eq value }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'md5_digest working ok' do
|
49
|
+
subject do
|
50
|
+
Crypto::Commons.md5_digest(value)
|
51
|
+
end
|
52
|
+
|
53
|
+
it { expect { subject }.not_to raise_error }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'hash working ok' do
|
57
|
+
subject do
|
58
|
+
Crypto::Commons.hash(value)
|
59
|
+
end
|
60
|
+
|
61
|
+
it { expect { subject }.not_to raise_error }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'hash_compare working ok' do
|
65
|
+
let(:hashed_value) { Crypto::Commons.hash(value) }
|
66
|
+
|
67
|
+
subject do
|
68
|
+
Crypto::Commons.hash_compare(hashed_value, value)
|
69
|
+
end
|
70
|
+
|
71
|
+
it { expect { subject }.not_to raise_error }
|
72
|
+
it { expect(subject).to be true }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'checksum working ok' do
|
76
|
+
let(:checksum_value) { Crypto::Commons.checksum(value) }
|
77
|
+
|
78
|
+
subject do
|
79
|
+
Crypto::Commons.checksum(value)
|
80
|
+
end
|
81
|
+
|
82
|
+
it { expect { subject }.not_to raise_error }
|
83
|
+
it { expect(subject).to eq checksum_value }
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'checksum512 working ok' do
|
87
|
+
let(:checksum_value) { Crypto::Commons.checksum512(value) }
|
88
|
+
|
89
|
+
subject do
|
90
|
+
Crypto::Commons.checksum512(value)
|
91
|
+
end
|
92
|
+
|
93
|
+
it { expect { subject }.not_to raise_error }
|
94
|
+
it { expect(subject).to eq checksum_value }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'sha256 working ok' do
|
98
|
+
subject do
|
99
|
+
Crypto::Commons.sha256('randomkey', value)
|
100
|
+
end
|
101
|
+
|
102
|
+
it { expect { subject }.not_to raise_error }
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Crypto::Encryptor' do
|
4
|
+
let(:options) { { value: '19999552059' } }
|
5
|
+
|
6
|
+
describe 'encrypt working ok' do
|
7
|
+
subject do
|
8
|
+
Crypto::Encryptor.encrypt(options, 'secret')
|
9
|
+
end
|
10
|
+
|
11
|
+
it { expect { subject }.not_to raise_error }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'decrypt working ok' do
|
15
|
+
before do
|
16
|
+
@encrypted_options = { value: Crypto::Encryptor.encrypt(options, 'secret') }
|
17
|
+
end
|
18
|
+
|
19
|
+
subject do
|
20
|
+
Crypto::Encryptor.decrypt(@encrypted_options, 'secret')
|
21
|
+
end
|
22
|
+
|
23
|
+
it { expect { subject }.not_to raise_error }
|
24
|
+
it { expect(subject).to eq options[:value] }
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Crypto::RSAKey' do
|
4
|
+
let(:passphrase) { '12345678' }
|
5
|
+
let(:private_key) { """
|
6
|
+
-----BEGIN RSA PRIVATE KEY-----
|
7
|
+
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
|
8
|
+
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
|
9
|
+
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
|
10
|
+
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
|
11
|
+
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
|
12
|
+
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
|
13
|
+
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
|
14
|
+
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
|
15
|
+
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
|
16
|
+
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
|
17
|
+
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
|
18
|
+
-----END RSA PRIVATE KEY-----
|
19
|
+
"""
|
20
|
+
}
|
21
|
+
|
22
|
+
describe 'sign works ok' do
|
23
|
+
test_cases = [
|
24
|
+
{
|
25
|
+
original_chain: '||0|EMPRESA|||APZ-450057199637|0|200.00|1|40||||40|a|846180000400000001|ND||40||||Concepto||||||2|1|T||3|0|0.00||',
|
26
|
+
signature: 'WAEYbfSFV/Ru5ccGA5gDjNo4RWKqNVuR/dKclmQFaVb2ThabPN/jzE5mIQHy8s8ii6G833xNvp/2VX5DWQSKV01JoJszrHpSOF34TvyQNO8WmfXR72b2HK+CVYtKX53JNkduj+dx9YjoqVAe5IWxTJrWBkm777VljocqaBUCEi4='
|
27
|
+
},
|
28
|
+
{
|
29
|
+
original_chain: '||40072|EMPRESA|20111111||RAS|90646|9999.99||||1234|||Beneficiario|5678||||||||||||REFCOB|7777||||||||',
|
30
|
+
signature: 'Xl8b7wc89X0JLwkwItKoctdOE4SliQ7z2JR/6XxkllkUiRQYQVWpvUeXznHnP3O1+/s+YNJqjK8kYaCZilJmgILKYeuLHTM67i/hJ9IyQHSqeyGSKBJOAJaZ4G5a+kGzIIl87X5rclaAYEEb1GrEM3P5GmUNOhkxan/I9wSVeds='
|
31
|
+
},
|
32
|
+
{
|
33
|
+
original_chain: '||846|XXXXXX|||123456789|90646|11.35|1|40|||||S.A. de C.V.|846180000000000016|||||||Prueba REST||||||123456||T||3||||',
|
34
|
+
signature: 'SuTOV+D7xJ3hzre+PDPfLhtBI0PS1ZjxRkDEnFg5Hdy/0I9S/9VthCo/zE4CBgyqR+mBGwUuuIFkjBidgJl7pdPVqalodg/VgLHlpf969qc76qpo918EkGZV3yPhxmL7AJcf4VYJgTXmvqLlYJsjVhzzTPFYe7YNxULZa94loRM='
|
35
|
+
}
|
36
|
+
]
|
37
|
+
|
38
|
+
test_cases.each do |test_case|
|
39
|
+
context "test case #{test_case[:original_chain]}" do
|
40
|
+
subject do
|
41
|
+
key = Crypto::RSAKey.new private_key, passphrase
|
42
|
+
key.seal(test_case[:original_chain])
|
43
|
+
end
|
44
|
+
|
45
|
+
it { expect { subject }.not_to raise_error }
|
46
|
+
it { expect(subject).to eq test_case[:signature] }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crypto_yellowme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yellowme
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bcrypt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.1.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activemodel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.17'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.17'
|
83
|
+
description: Crypto is Yellowme's ruby crypto & security utilities gem
|
84
|
+
email: hola@yellowme.mx
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- MIT-LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- crypto.gemspec
|
97
|
+
- lib/crypto.rb
|
98
|
+
- lib/crypto/commons.rb
|
99
|
+
- lib/crypto/config.rb
|
100
|
+
- lib/crypto/encryptor.rb
|
101
|
+
- lib/crypto/rsa_key.rb
|
102
|
+
- lib/crypto/version.rb
|
103
|
+
- spec/crypto/commons_spec.rb
|
104
|
+
- spec/crypto/encryptor_spec.rb
|
105
|
+
- spec/crypto/rsa_key_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: https://github.com/yellowme/crypto-ruby
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.7.6
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Crypto is Yellowme's lib for crypto & security
|
131
|
+
test_files:
|
132
|
+
- spec/crypto/commons_spec.rb
|
133
|
+
- spec/crypto/encryptor_spec.rb
|
134
|
+
- spec/crypto/rsa_key_spec.rb
|
135
|
+
- spec/spec_helper.rb
|