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

40 lines
762 B
Ruby

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