aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/src/rw/ut_large/gen/main.cpp
blob: c93d5dde76104b456dbd724f2de9f49ea38874fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <library/cpp/tvmauth/src/rw/keys.h>

#include <library/cpp/string_utils/base64/base64.h> 

#include <util/generic/yexception.h>

using namespace NTvmAuth;

const TString DATA = "my magic data";

int main(int, char**) {
    const NRw::TKeyPair pair = NRw::GenKeyPair(1024);
    const NRw::TRwPrivateKey priv(pair.Private, 0);
    const NRw::TRwPublicKey pub(pair.Public);

    Cout << "data='" << DATA << "'."
         << "private='" << Base64Encode(pair.Private) << "'."
         << "public='" << Base64Encode(pair.Public) << "'.";

    TString sign;
    try {
        sign = priv.SignTicket(DATA);
        Cout << "sign='" << Base64Encode(sign) << "'.";
        Y_ENSURE(pub.CheckSign(DATA, sign));
    } catch (const std::exception& e) {
        Cout << "what='" << e.what() << "'" << Endl;
        return 1;
    }
    Cout << Endl;

    return 0;
}