読者です 読者をやめる 読者になる 読者になる

crypto, public_key のメモ

erlang

http://groups.google.com/group/erlang-programming/msg/7679cd93919c7a9d

-module(crypttest).
-include_lib("public_key/include/public_key.hrl").
-export([testcase/0]).

testcase() ->
   {ok,[Entry]} = public_key:pem_to_der("./test_private_key"),
   {ok,{'RSAPrivateKey', 'two-prime', N , E, D, _P, _Q, _E1, _E2, _C, _Other}} = public_key:decode_private_key(Entry),
   PlainText = "now is the time for all good men to come to the aid of their country",
   PrivKey = [crypto:mpint(E), crypto:mpint(N), crypto:mpint(D)] ,
   PubKey = [crypto:mpint(E), crypto:mpint(N)],
   Foo = crypto:rsa_private_encrypt(PlainText,PrivKey,rsa_pkcs1_padding),
   Bar = crypto:rsa_public_decrypt(Foo,PubKey,rsa_pkcs1_padding),
   PlainText == binary_to_list(Bar).