From 6a39173d1ebf8f0d34be356dd7253b5b67b3e9f4 Mon Sep 17 00:00:00 2001 From: Andrey Mayorov Date: Wed, 1 Mar 2017 23:02:32 +0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + rebar.config | 1 + rebar.lock | 1 + src/genecpubkey.app.src | 17 +++++++++++++++++ src/genecpubkey.erl | 16 ++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 .gitignore create mode 100644 rebar.config create mode 100644 rebar.lock create mode 100644 src/genecpubkey.app.src create mode 100644 src/genecpubkey.erl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e35d885 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +_build diff --git a/rebar.config b/rebar.config new file mode 100644 index 0000000..80ca3fb --- /dev/null +++ b/rebar.config @@ -0,0 +1 @@ +{escript_emu_args, "%%! +sbtu +A0 -noshell -boot start_clean\n"}. diff --git a/rebar.lock b/rebar.lock new file mode 100644 index 0000000..57afcca --- /dev/null +++ b/rebar.lock @@ -0,0 +1 @@ +[]. diff --git a/src/genecpubkey.app.src b/src/genecpubkey.app.src new file mode 100644 index 0000000..57108f7 --- /dev/null +++ b/src/genecpubkey.app.src @@ -0,0 +1,17 @@ +{application, genecpubkey, [ + {description, "Generate PEM file with EC Public key from EC Private key"}, + {vsn, "0"}, + {registered, []}, + {applications, [ + kernel, + stdlib, + public_key + ]}, + {env, []}, + {modules, []}, + {maintainers, [ + "Andrew Mayorov " + ]}, + {licenses, []}, + {links, []} +]}. diff --git a/src/genecpubkey.erl b/src/genecpubkey.erl new file mode 100644 index 0000000..50bbfb5 --- /dev/null +++ b/src/genecpubkey.erl @@ -0,0 +1,16 @@ +-module(genecpubkey). + +-export([main/1]). + +-spec main([string()]) -> no_return(). + +main([PrivKeyPEMFilename, PubKeyPEMFilename]) -> + {ok, PrivKeyPEMBin} = file:read_file(PrivKeyPEMFilename), + [PrivKeyPEMEntry] = public_key:pem_decode(PrivKeyPEMBin), + [PrivKeyPEMEntry] = public_key:pem_decode(PrivKeyPEMBin), + PrivKey = public_key:pem_entry_decode(PrivKeyPEMEntry), + {'ECPrivateKey', 1, _, ECParams, PublicKey} = PrivKey, + PubKey = {{'ECPoint', PublicKey}, ECParams}, + PubKeyPEMEntry = public_key:pem_entry_encode('SubjectPublicKeyInfo', PubKey), + PubKeyPEMBin = public_key:pem_encode([PubKeyPEMEntry]), + ok = file:write_file(PubKeyPEMFilename, PubKeyPEMBin).