basicssl 1.0.0

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.
Files changed (2) hide show
  1. data/lib/basic_ssl.rb +36 -0
  2. metadata +55 -0
@@ -0,0 +1,36 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+
4
+ module BasicSSL
5
+
6
+ class << self
7
+
8
+ ## Returns an Base64 encoded string with encryption
9
+ def encrypt(key, string)
10
+ Base64.encode64(rsa_key(key).public_encrypt(string))
11
+ end
12
+
13
+ ## Return the raw string after decryption & decoding
14
+ def decrypt(key, string)
15
+ rsa_key(key).private_decrypt(Base64.decode64(string))
16
+ end
17
+
18
+ ## Return a signature for the string
19
+ def sign(key, string)
20
+ Base64.encode64(rsa_key(key).sign(OpenSSL::Digest::SHA1.new, string))
21
+ end
22
+
23
+ ## Verify the string and signature
24
+ def verify(key, signature, string)
25
+ rsa_key(key).verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), string)
26
+ end
27
+
28
+ private
29
+
30
+ def rsa_key(key)
31
+ OpenSSL::PKey::RSA.new(key)
32
+ end
33
+
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basicssl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-25 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: adam@atechmedia.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/basic_ssl.rb
26
+ has_rdoc: true
27
+ homepage: http://github.com/adamcooke/basicssl
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Basic encryption and signing wrapper
54
+ test_files: []
55
+