1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/interactors/create_rsa_keys.rb

41 lines
762 B
Ruby
Raw Normal View History

2019-09-10 12:18:21 -04:00
# frozen_string_literal: true
class CreateRSAKeys
include Interactor
BITS = 4096
2019-09-11 18:04:23 -04:00
before :set_pkey
before :set_ciphertext
2019-09-10 12:18:21 -04:00
def call
2019-09-11 18:04:23 -04:00
context.public_key = RSAPublicKey.create!(
bits: BITS,
public_key_pem: @pkey.public_key.to_pem.freeze,
private_key_pem: @pkey.to_pem.freeze,
2019-09-11 18:04:23 -04:00
private_key_pem_iv: @iv,
private_key_pem_secret: @key,
2019-09-11 18:04:23 -04:00
private_key_pem_ciphertext: @ciphertext,
)
end
private
2019-09-10 12:18:21 -04:00
2019-09-11 18:04:23 -04:00
def set_pkey
@pkey = OpenSSL::PKey::RSA.new BITS
end
def set_ciphertext
cipher = OpenSSL::Cipher::AES256.new
cipher.encrypt
2019-09-11 18:04:23 -04:00
@iv = cipher.random_iv.freeze
@key = cipher.random_key.freeze
2019-09-11 18:04:23 -04:00
@ciphertext = [
cipher.update(@pkey.to_pem),
cipher.final,
].join.freeze
2019-09-10 12:18:21 -04:00
end
end