-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
92 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Adminterface | ||
module Encryption | ||
class Encryptor | ||
extend Callable | ||
attr_reader :message | ||
|
||
def initialize(message) | ||
@message = message | ||
end | ||
|
||
def call | ||
Base64.encode64(public_key.public_encrypt(message)) | ||
end | ||
|
||
private | ||
|
||
def public_key_file | ||
@public_key_file ||= File.read(Engine.root.join("lib/adminterface/public.pem")) | ||
end | ||
|
||
def public_key | ||
@public_key ||= OpenSSL::PKey::RSA.new(public_key_file) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuH2AdyyQycs7DhFQo1f/ | ||
9ssIqc5ek7OYZHlfwSYSFuWaTfq46HK66QZ1ebkUva/U33QzNyaxcMxYpTpRY2dF | ||
IPLtS1QNktC4U0T3Nz0sY3tZp/IwnWcE9b8MpS2FDFtMRiHu+/dtthWoG6kP6w5y | ||
P8pWDLwQuYPbPnqlLbp6yWaJB1G1qHoLmgKD1VPUxjk0gB0tGPPvaiciESObbGC3 | ||
IgzeUKtz/+dhR4UBOZc1pmrftwacUfvNHrSuot0jaYCNrb98Oq8kkBpp79MgRghK | ||
SkPdTRidSlIokdxlEOrcRhoJsVka5w9fYLShJdv1yhmGh3VZdKkvSqM7MhwE+zML | ||
0QIDAQAB | ||
-----END PUBLIC KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Adminterface.setup do |config| | ||
config.license_key = "FAKE_KEY" | ||
# config.license_key = "FAKE_KEY" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "test_helper" | ||
|
||
module Encryption | ||
class EncryptorTest < ActiveSupport::TestCase | ||
def described_class | ||
Adminterface::Encryption::Encryptor | ||
end | ||
|
||
def base64?(value) | ||
value.is_a?(String) && Base64.encode64(Base64.decode64(value)).eql?(value) | ||
end | ||
|
||
test "encrypts message" do | ||
message = "test" | ||
encrypted_message = described_class.call(message) | ||
assert_not_equal message, encrypted_message | ||
assert_not_equal message, Base64.decode64(encrypted_message) | ||
end | ||
|
||
test "returns encrypted message in base64 format" do | ||
message = "test" | ||
encrypted_message = described_class.call(message) | ||
assert base64?(encrypted_message) | ||
end | ||
|
||
test "uses a public key" do | ||
service = described_class.new("test") | ||
refute service.send(:public_key).private? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters