fix rsa
This commit is contained in:
parent
376c5a22d4
commit
3adb2d33ec
@ -14,9 +14,13 @@
|
||||
|
||||
%% 解密数据
|
||||
decode(EncBin) when is_binary(EncBin) ->
|
||||
PrivateKey = private_key(),
|
||||
public_key:decrypt_private(EncBin, PrivateKey).
|
||||
%PrivateKey = private_key(),
|
||||
%public_key:decrypt_private(EncBin, PrivateKey).
|
||||
ok.
|
||||
|
||||
%% 解密数据
|
||||
encode(Data, PublicKey) when is_binary(Data), is_binary(PublicKey) ->
|
||||
ok.
|
||||
PubBin = <<"-----BEGIN PUBLIC KEY-----\n", PublicKey/binary, "-----END PUBLIC KEY-----">>,
|
||||
[Pub] = public_key:pem_decode(PubBin),
|
||||
PubKey = public_key:pem_entry_decode(Pub),
|
||||
public_key:encrypt_public(Data, PubKey).
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
%% API
|
||||
-export([insert_hosts/0]).
|
||||
-export([rsa_encode/1]).
|
||||
|
||||
insert_hosts() ->
|
||||
lists:foreach(fun(Id0) ->
|
||||
@ -24,4 +25,41 @@ insert_hosts() ->
|
||||
},
|
||||
|
||||
host_model:add_host(Host)
|
||||
end, lists:seq(1, 100)).
|
||||
end, lists:seq(1, 100)).
|
||||
|
||||
|
||||
rsa_encode(Data) when is_binary(Data) ->
|
||||
%% 读取相关配置
|
||||
PublicPemFile = "/tmp/keys/public.pem",
|
||||
|
||||
%% 私钥保存解析后的
|
||||
{ok, PubBin} = file:read_file(PublicPemFile),
|
||||
lager:debug("pub bin is: ~p", [PubBin]),
|
||||
[Pub] = public_key:pem_decode(PubBin),
|
||||
lager:debug("pub pem bin is: ~p", [Pub]),
|
||||
PubKey = public_key:pem_entry_decode(Pub),
|
||||
lager:debug("the public key is: ~p", [PubKey]),
|
||||
|
||||
EncData = public_key:encrypt_public(Data, PubKey),
|
||||
lager:debug("enc data is: ~p", [EncData]),
|
||||
|
||||
rsa_decode(EncData),
|
||||
|
||||
ok.
|
||||
|
||||
rsa_decode(EncData) when is_binary(EncData) ->
|
||||
%% 读取相关配置
|
||||
PublicPemFile = "/tmp/keys/pri.pem",
|
||||
|
||||
%% 私钥保存解析后的
|
||||
{ok, PubBin} = file:read_file(PublicPemFile),
|
||||
lager:debug("pub bin is: ~p", [PubBin]),
|
||||
[Pub] = public_key:pem_decode(PubBin),
|
||||
lager:debug("pub pem bin is: ~p", [Pub]),
|
||||
PubKey = public_key:pem_entry_decode(Pub),
|
||||
lager:debug("the public key is: ~p", [PubKey]),
|
||||
|
||||
PlainData = public_key:decrypt_private(EncData, PubKey),
|
||||
lager:debug("plain data is: ~p", [PlainData]),
|
||||
|
||||
ok.
|
||||
@ -13,8 +13,8 @@
|
||||
[iot,
|
||||
sasl]},
|
||||
|
||||
% {mode, dev},
|
||||
{mode, prod},
|
||||
{mode, dev},
|
||||
%{mode, prod},
|
||||
|
||||
%% automatically picked up if the files
|
||||
%% exist but can be set manually, which
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user