]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/testcrypto.cc
1 #include "auth/Crypto.h"
2 #include "common/Clock.h"
4 #include "common/config.h"
5 #include "common/debug.h"
7 #define dout_subsys ceph_subsys_auth
11 #define dout_context g_ceph_context
13 int main(int argc
, char *argv
[])
15 char aes_key
[AES_KEY_LEN
];
16 memset(aes_key
, 0x77, sizeof(aes_key
));
17 bufferptr
keybuf(aes_key
, sizeof(aes_key
));
18 CryptoKey
key(CEPH_CRYPTO_AES
, ceph_clock_now(), keybuf
);
20 const char *msg
="hello! this is a message\n";
23 bufferptr
ptr(msg
, strlen(msg
));
26 enc_in
.append(msg
, strlen(msg
));
30 if (key
.encrypt(g_ceph_context
, enc_in
, enc_out
, &error
) < 0) {
31 assert(!error
.empty());
32 dout(0) << "couldn't encode! error " << error
<< dendl
;
36 const char *enc_buf
= enc_out
.c_str();
37 for (unsigned i
=0; i
<enc_out
.length(); i
++) {
38 std::cout
<< hex
<< (int)(unsigned char)enc_buf
[i
] << dec
<< " ";
40 std::cout
<< std::endl
;
43 bufferlist dec_in
, dec_out
;
47 if (key
.decrypt(g_ceph_context
, dec_in
, dec_out
, &error
) < 0) {
48 assert(!error
.empty());
49 dout(0) << "couldn't decode! error " << error
<< dendl
;
53 dout(0) << "decoded len: " << dec_out
.length() << dendl
;
54 dout(0) << "decoded msg: " << dec_out
.c_str() << dendl
;