encrypted_field 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e65c038c23e5c47236686f8ba756e8588339f0c4
4
- data.tar.gz: 435e08155cdb3a6430fb25409ab1d74140dd98a1
3
+ metadata.gz: 893b3d14ad9dd9026cb9db5a43772636c0f0a408
4
+ data.tar.gz: 41f51c9792157cc0132c5f012672dbe6f75a3e04
5
5
  SHA512:
6
- metadata.gz: 0e80af16bd44cf71c3fc78fed3a9588e3b4346db5eb30f54e89d0f570565a94f8846a3c739be52e956846dcd40fc43977519ceb57a1bd471ea1cbb61759090c8
7
- data.tar.gz: a2148593c775e4c74f6ac1497ee6430f3e70c340504ab6f46449cb2340fbeec5af88e42479123e5ea9f561939a98c5e93f8df211d23488a4e19cf3c36f0351cc
6
+ metadata.gz: 908e6488ddf661e78c45e8a4002ceda346807b3f3e2120498e92967579d7904b4fac462e6da31cbf2d78142a426a60e726510ef1ba299c1629e8ac1d13232b71
7
+ data.tar.gz: 317c0334fe2fd5d3f2b0ed6ade673a4faacd9fb32f2cf3882896cd8fc11a5c63a8bc9385473355ed9c9df5f7d765edcec1fb59ed3e128e2d676ca8e5692323de
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /vendor/bundle/
10
+ /vendor/bundle
@@ -0,0 +1,9 @@
1
+ module EncryptedField
2
+ module ActionView
3
+ def encrypted_field_public_key
4
+ @public_key ||= File.read("#{ENV['CONFIG_CERTIFICATE_PATH']}/encrypted_field_public_key.pem")
5
+ end
6
+
7
+ ::ActionView::Base.send :include, self
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'active_support/concern'
2
+
3
+ module EncryptedField
4
+ module ControllerAdditions
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ def decrypt_encrypted_field(value)
8
+ @private_key ||= OpenSSL::PKey::RSA.new(File.read("#{ENV['CONFIG_CERTIFICATE_PATH']}/encrypted_field_private_key.pem"))
9
+ @private_key.private_decrypt(Base64.decode64(value))
10
+ end
11
+ def encrypt_encrypted_field(value)
12
+ @private_key ||= OpenSSL::PKey::RSA.new(File.read("#{ENV['CONFIG_CERTIFICATE_PATH']}/encrypted_field_public_key.pem"))
13
+ Base64.encode64(@private_key.public_encrypt(value))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class EncryptedField::Railtie < Rails::Railtie
2
+ rake_tasks do
3
+ load 'tasks/generate_keypair.rake'
4
+ end
5
+
6
+ initializer "will_paginate" do |app|
7
+ ActiveSupport.on_load :action_view do
8
+ require 'encrypted_field/action_view'
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module EncryptedField
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,6 +1,12 @@
1
1
  require "encrypted_field/version"
2
+ require 'encrypted_field/controller_additions'
3
+ require "encrypted_field/railtie" if defined?(Rails)
2
4
  require "openssl"
3
5
 
4
6
  module EncryptedField
5
- class Engine < ::Rails::Engine; end
7
+ class Engine < ::Rails::Engine
8
+ initializer :assets do |config|
9
+ Rails.application.config.assets.paths << root.join("vendor", "assets")
10
+ end
11
+ end
6
12
  end
@@ -4,7 +4,7 @@ namespace :keypair do
4
4
  rsa_key = OpenSSL::PKey::RSA.new(2048)
5
5
  private_key = rsa_key.to_pem
6
6
  public_key = rsa_key.public_key.to_pem
7
- path = (args[:path] || '.')
7
+ path = (args[:path] || ENV['CONFIG_CERTIFICATE_PATH'] || '.')
8
8
 
9
9
  File.open("#{path}/encrypted_field_public_key.pem", "w+") do |f|
10
10
  f.write public_key
@@ -0,0 +1,15 @@
1
+ //= require jsencrypt
2
+
3
+ $(document).on('turbolinks:load', function(){
4
+ $('form').submit(function( event ) {
5
+ var encrypt = new JSEncrypt();
6
+ $('[data-encrypt]').each(function(){
7
+ unencrypted = $(this);
8
+ encrypt.setKey($('#public_key').val());
9
+ encrypted = encrypt.encrypt(unencrypted.val());
10
+ if (encrypted != false) {
11
+ unencrypted.val(encrypted);
12
+ }
13
+ })
14
+ });
15
+ });