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

32 lines
704 B
Ruby

# frozen_string_literal: true
class CreateRSAKeys
include Interactor
BITS = 4096
def call
pkey = OpenSSL::PKey::RSA.new BITS
context.private_key_pem = pkey.to_pem.freeze
cipher = OpenSSL::Cipher::AES256.new
cipher.encrypt
context.private_key_pem_key = cipher.random_key.freeze
private_key_pem_iv = cipher.random_iv
private_key_pem_ciphertext = [
cipher.update(context.private_key_pem),
cipher.final,
].join.freeze
context.public_key = RSAPublicKey.create!(
bits: BITS,
pem: pkey.public_key.to_pem.freeze,
private_key_pem_iv: private_key_pem_iv,
private_key_pem_ciphertext: private_key_pem_ciphertext,
)
end
end