aescrypt 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of aescrypt might be problematic. Click here for more details.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +79 -0
- data/Rakefile +2 -0
- data/aescrypt.gemspec +16 -0
- data/lib/aescrypt.rb +82 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Gurpartap Singh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# AESCrypt - Simple AES encryption / decryption for Ruby
|
2
|
+
|
3
|
+
AESCrypt is a simple to use, opinionated AES encryption / decryption Ruby gem that just works.
|
4
|
+
|
5
|
+
AESCrypt uses the AES-256-CBC cipher and encodes the encrypted data with Base64.
|
6
|
+
|
7
|
+
A corresponding gem to easily handle AES encryption / decryption in Objective-C is available at http://github.com/Gurpartap/AESCrypt-ObjC.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'aescrypt'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install aescrypt
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
message = "top secret message"
|
26
|
+
password = "p4ssw0rd"
|
27
|
+
|
28
|
+
Encrypting
|
29
|
+
|
30
|
+
encrypted_data = AESCrypt.encrypt(message, password)
|
31
|
+
|
32
|
+
Decrypting
|
33
|
+
|
34
|
+
message = AESCrypt.decrypt(encrypted_data, password)
|
35
|
+
|
36
|
+
## Advanced usage
|
37
|
+
|
38
|
+
Encrypting
|
39
|
+
|
40
|
+
encrypted_data = encrypt_data(data, key, iv, cipher_type)
|
41
|
+
|
42
|
+
Decrypting
|
43
|
+
|
44
|
+
decrypted_data = decrypt_data(encrypted_data, key, iv, cipher_type)
|
45
|
+
|
46
|
+
## Corresponding usage in Objective-C
|
47
|
+
|
48
|
+
The AESCrypt Objective-C class, available at https://github.com/Gurpartap/AESCrypt-ObjC, understands what you're talking about in your Ruby code. The purpose of the Ruby gem and Objective-C class is to have something that works out of the box across the server (Ruby) and client (Objective-C). However, a standard encryption technique is implemented, which ensures that you can handle the data with any AES compatible library available across the web. So, you're not locked-in.
|
49
|
+
|
50
|
+
Here's how you would use the AESCrypt Objective-C class:
|
51
|
+
|
52
|
+
NSString *message = @"top secret message";
|
53
|
+
NSString *password = @"p4ssw0rd";
|
54
|
+
|
55
|
+
Encrypting
|
56
|
+
|
57
|
+
NSString *encryptedData = [AESCrypt encrypt:message password:password];
|
58
|
+
|
59
|
+
Decrypting
|
60
|
+
|
61
|
+
NSString *message = [AESCrypt decrypt:encryptedData password:password];
|
62
|
+
|
63
|
+
See the Objective-C class README at http://github.com/Gurpartap/AESCrypt-ObjC for more details.
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
Copyright (c) 2012 Gurpartap Singh
|
68
|
+
|
69
|
+
The encrypt_data and decrypt_data methods are Copyright (c) 2007 Brent Sowers and have been included in the gem with prior permission. Thanks Brent! :)
|
70
|
+
|
71
|
+
See LICENSE for license terms.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/aescrypt.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Gurpartap Singh"]
|
5
|
+
gem.email = ["contact@gurpartap.com"]
|
6
|
+
gem.description = "Simple AES encryption / decryption for Ruby"
|
7
|
+
gem.summary = "AESCrypt is a simple to use, opinionated AES encryption / decryption Ruby gem that just works."
|
8
|
+
gem.homepage = "http://github.com/Gurpartap/aescrypt"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.name = "aescrypt"
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
gem.version = "1.0.0"
|
14
|
+
|
15
|
+
gem.add_development_dependency "rake"
|
16
|
+
end
|
data/lib/aescrypt.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# The encrypt_data and decrypt_data methods are Copyright (c) 2007 Brent Sowers
|
4
|
+
# and have been included with prior permission.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2012 Gurpartap Singh
|
7
|
+
#
|
8
|
+
# MIT License
|
9
|
+
#
|
10
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
# a copy of this software and associated documentation files (the
|
12
|
+
# "Software"), to deal in the Software without restriction, including
|
13
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
# the following conditions:
|
17
|
+
#
|
18
|
+
# The above copyright notice and this permission notice shall be
|
19
|
+
# included in all copies or substantial portions of the Software.
|
20
|
+
#
|
21
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
22
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
24
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
25
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
26
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
27
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
|
+
|
29
|
+
require 'openssl'
|
30
|
+
|
31
|
+
module AESCrypt
|
32
|
+
def self.encrypt(message, password)
|
33
|
+
Base64.encode64(self.encrypt_data(message.to_s.strip, self.key_digest(password), nil, "AES-256-CBC"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.decrypt(message, password)
|
37
|
+
base64_decoded = Base64.decode64(message.to_s.strip)
|
38
|
+
self.decrypt_data(base64_decoded, self.key_digest(password), nil, "AES-256-CBC")
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.key_digest(password)
|
42
|
+
OpenSSL::Digest::SHA256.new(password).digest
|
43
|
+
end
|
44
|
+
|
45
|
+
# Decrypts a block of data (encrypted_data) given an encryption key
|
46
|
+
# and an initialization vector (iv). Keys, iv's, and the data
|
47
|
+
# returned are all binary strings. Cipher_type should be
|
48
|
+
# "AES-256-CBC", "AES-256-ECB", or any of the cipher types
|
49
|
+
# supported by OpenSSL. Pass nil for the iv if the encryption type
|
50
|
+
# doesn't use iv's (like ECB).
|
51
|
+
#:return: => String
|
52
|
+
#:arg: encrypted_data => String
|
53
|
+
#:arg: key => String
|
54
|
+
#:arg: iv => String
|
55
|
+
#:arg: cipher_type => String
|
56
|
+
def self.decrypt_data(encrypted_data, key, iv, cipher_type)
|
57
|
+
aes = OpenSSL::Cipher::Cipher.new(cipher_type)
|
58
|
+
aes.decrypt
|
59
|
+
aes.key = key
|
60
|
+
aes.iv = iv if iv != nil
|
61
|
+
aes.update(encrypted_data) + aes.final
|
62
|
+
end
|
63
|
+
|
64
|
+
# Encrypts a block of data given an encryption key and an
|
65
|
+
# initialization vector (iv). Keys, iv's, and the data returned
|
66
|
+
# are all binary strings. Cipher_type should be "AES-256-CBC",
|
67
|
+
# "AES-256-ECB", or any of the cipher types supported by OpenSSL.
|
68
|
+
# Pass nil for the iv if the encryption type doesn't use iv's (like
|
69
|
+
# ECB).
|
70
|
+
#:return: => String
|
71
|
+
#:arg: data => String
|
72
|
+
#:arg: key => String
|
73
|
+
#:arg: iv => String
|
74
|
+
#:arg: cipher_type => String
|
75
|
+
def self.encrypt_data(data, key, iv, cipher_type)
|
76
|
+
aes = OpenSSL::Cipher::Cipher.new(cipher_type)
|
77
|
+
aes.encrypt
|
78
|
+
aes.key = key
|
79
|
+
aes.iv = iv if iv != nil
|
80
|
+
aes.update(data) + aes.final
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aescrypt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gurpartap Singh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Simple AES encryption / decryption for Ruby
|
31
|
+
email:
|
32
|
+
- contact@gurpartap.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- aescrypt.gemspec
|
43
|
+
- lib/aescrypt.rb
|
44
|
+
homepage: http://github.com/Gurpartap/aescrypt
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
hash: 1373182486440895594
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
hash: 1373182486440895594
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.24
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: AESCrypt is a simple to use, opinionated AES encryption / decryption Ruby
|
74
|
+
gem that just works.
|
75
|
+
test_files: []
|