minienigma 0.0.2
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/minienigma.rb +49 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 855e5299edce5419bec871a83d89cc709f980681
|
4
|
+
data.tar.gz: 39710d746f40f61b437476f1ef9a8749e8fb0a62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f0557216ebcf06733568a71ed2692f6eae02e8da0d528fdb0c64d3dc3961cd9a3375ca98ed051804275721de6a3c4101070daf6d8aa081aa86c8b377de85166
|
7
|
+
data.tar.gz: 0c0e8c797b12ce6d2cd20a95dce47ff0b7e8c299b5c3139c44242ad956c11e8f8bd1d12289ee2745281801854fdfd1eb2cf4b3ec7787b55b960c960d41f0904d
|
data/lib/minienigma.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
class MiniEnigma
|
5
|
+
@@key = 'vL3axd1kxy5BSLL8fdGqg2tHWkSWAcD8'
|
6
|
+
@@iv = '84DF5FCE8F76C548'
|
7
|
+
|
8
|
+
def self.configure(key, iv)
|
9
|
+
@@key = key
|
10
|
+
@@iv = iv
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.keys
|
14
|
+
puts "Key: #{@@key} - IV: #{@@iv}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encrypt(data)
|
18
|
+
self.validate_config
|
19
|
+
raise "Data to encrypt cannot be empty" if (data == nil or data.empty?)
|
20
|
+
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
|
21
|
+
cipher.encrypt
|
22
|
+
cipher.key = @@key
|
23
|
+
cipher.iv = @@iv
|
24
|
+
encrypted_data = cipher.update(data) + cipher.final
|
25
|
+
return Base64.encode64(encrypted_data).encode('utf-8')
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.decrypt(data)
|
29
|
+
self.validate_config
|
30
|
+
begin
|
31
|
+
decipher = OpenSSL::Cipher::AES.new(256, :CBC)
|
32
|
+
decipher.decrypt
|
33
|
+
decipher.key = @@key
|
34
|
+
decipher.iv = @@iv
|
35
|
+
plain_data = decipher.update(Base64.decode64(data)) + decipher.final
|
36
|
+
return plain_data.force_encoding('UTF-8')
|
37
|
+
rescue Exception => e
|
38
|
+
puts e.backtrace
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def self.validate_config
|
45
|
+
raise "Invalid Key, it must be 32 characters long" if (@@key == nil or @@key.length != 32)
|
46
|
+
raise "Invalid IV, it must be 16 characters long" if (@@iv == nil or @@iv.length != 16)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minienigma
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Esteban Ochoa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Miniemigma uses an AES 256 bit CBC algorithm for encrypting and decrypting
|
14
|
+
strings. Encrypted strings are returned using a Base64 encoding. http://randomkeygen.com
|
15
|
+
email: esteban8a@innventto.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/minienigma.rb
|
21
|
+
homepage: http://rubygems.org/gems/minienigma
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.1.10
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Minienigma provides a very simple and easy to use mechanism to encrypt and
|
45
|
+
decrypt messages.
|
46
|
+
test_files: []
|