<commit_before>%%%-------------------------------------------------------------------
%%% @author simon
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 20. 七月 2017 21:40
%%%-------------------------------------------------------------------
-module(utils_enckey).
-author("simon").

%% API
-export([
  load_private_key/1
  , load_private_key/2
  , load_public_key/1
]).

%%==================================================================
load_private_key(KeyFileName) ->
  load_private_key(KeyFileName, "").

load_private_key(KeyFileName, Pwd) ->
  {ok, PemBin} = file:read_file(KeyFileName),
  [RSAEntry | _Rest] = public_key:pem_decode(PemBin),
  RsaKeyInfo = public_key:pem_entry_decode(RSAEntry, Pwd),
  lager:debug("private key = ~p", [RsaKeyInfo]),
  {ok, RsaKeyInfo}.


%%==================================================================
load_public_key(KeyFileName) ->
  {ok, PemBin} = file:read_file(KeyFileName),
  [Certificate] = public_key:pem_decode(PemBin),
  PublicKey = public_key:pem_entry_decode(Certificate),
  lager:debug("public key = ~p", [PublicKey]),
  {ok, PublicKey}.<commit_msg>change load_private_key/load_public_key logic according to orig unionpay_config.erl<commit_after>%%%-------------------------------------------------------------------
%%% @author simon
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 20. 七月 2017 21:40
%%%-------------------------------------------------------------------
-module(utils_enckey).
-include_lib("public_key/include/public_key.hrl").
-author("simon").

%% API
-export([
  load_private_key/1
  , load_private_key/2
  , load_public_key/1
]).

%%==================================================================
load_private_key(KeyFileName) ->
  load_private_key(KeyFileName, "").

load_private_key(KeyFileName, Pwd) ->
  {ok, PemBin} = file:read_file(KeyFileName),
  [RSAEntry | _Rest] = public_key:pem_decode(PemBin),
  RsaKeyInfo = public_key:pem_entry_decode(RSAEntry, Pwd),
  RsaKey = public_key:der_decode('RSAPrivateKey', RsaKeyInfo#'PrivateKeyInfo'.privateKey),
  lager:debug("private key = ~p", [RsaKeyInfo]),
  RsaKey.
%%  lager:debug("private key = ~p", [RsaKeyInfo]),
%%  {ok, RsaKeyInfo}.


%%==================================================================
load_public_key(KeyFileName) ->
  {ok, PemBin} = file:read_file(KeyFileName),
  [Certificate] = public_key:pem_decode(PemBin),
  {_, DerCert, _} = Certificate,
  Decoded = public_key:pkix_decode_cert(DerCert, otp),
  PublicKey = Decoded#'OTPCertificate'.tbsCertificate#'OTPTBSCertificate'.subjectPublicKeyInfo#'OTPSubjectPublicKeyInfo'.subjectPublicKey,
  lager:debug("public key = ~p", [PublicKey]),
  PublicKey.
%%  PublicKey = public_key:pem_entry_decode(Certificate),
%%  lager:debug("public key = ~p", [PublicKey]),
%%  {ok, PublicKey}.
{'fraction_non_alphanumeric': 0.32826855123674914, 'fraction_numerical': 0.012014134275618375, 'mean_word_length': 3.790186125211506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5070563', 'n_tokens_mistral': 956, 'n_tokens_neox': 904, 'n_words': 134}