progress???
All checks were successful
Build & Test / nix-build (push) Successful in 1m28s

This commit is contained in:
Kodi Craft 2024-10-05 11:27:10 +02:00
parent 3f0e0ae22f
commit 80060b1708
Signed by: kodi
GPG Key ID: 69D9EED60B242822

View File

@ -30,10 +30,6 @@ defmodule Amethyst.Keys do
GenServer.start_link(__MODULE__, bits, name: __MODULE__) GenServer.start_link(__MODULE__, bits, name: __MODULE__)
end end
def get_priv do
GenServer.call(__MODULE__, :get_priv)
end
def get_pub do def get_pub do
GenServer.call(__MODULE__, :get_pub) GenServer.call(__MODULE__, :get_pub)
end end
@ -52,22 +48,19 @@ defmodule Amethyst.Keys do
rsa_public_key = {:RSAPublicKey, modulus, public_exponent} rsa_public_key = {:RSAPublicKey, modulus, public_exponent}
Logger.info("Generated RSA keys") Logger.info("Generated RSA keys")
{:ok, {rsa_public_key, rsa_private_key}} {:ok, {rsa_public_key, rsa_private_key, bits}}
end end
@impl true @impl true
def handle_call(:get_priv, _from, {pubkey, privkey}) do def handle_call(:get_pub, _from, {pubkey, privkey, bits}) do
{:reply, :public_key.der_encode(:RSAPrivateKey, privkey), {pubkey, privkey}} {:SubjectPublicKeyInfo, pk, :not_encrypted} = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, pubkey)
# Logger.debug("#{inspect(pem_encoded, limit: :infinity)}")
{:reply, pk, {pubkey, privkey, bits}}
end end
@impl true @impl true
def handle_call(:get_pub, _from, {pubkey, privkey}) do def handle_call({:decrypt, encrypted}, _from, {pubkey, privkey, bits}) do
{:reply, :public_key.der_encode(:RSAPublicKey, pubkey), {pubkey, privkey}}
end
@impl true
def handle_call({:decrypt, encrypted}, _from, {pubkey, privkey}) do
plaintext = :public_key.decrypt_private(encrypted, privkey) plaintext = :public_key.decrypt_private(encrypted, privkey)
{:reply, plaintext, {pubkey, privkey}} {:reply, plaintext, {pubkey, privkey, bits}}
end end
end end