commit 6a39173d1ebf8f0d34be356dd7253b5b67b3e9f4 Author: Andrey Mayorov Date: Wed Mar 1 23:02:32 2017 +0300 Initial commit 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).