-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.hpp
More file actions
23 lines (20 loc) · 676 Bytes
/
Copy pathcode.hpp
File metadata and controls
23 lines (20 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <openssl/sha.h>
#define CODE 48
class Code {
private:
unsigned char data[CODE];
unsigned char hash[SHA256_DIGEST_LENGTH]; // 32 bajty = 256 bitów
std::string base;
std::string encode(const unsigned char*, size_t) const;
public:
Code();
void draw();
std::string base64() { return base; }
void encode() { base = encode(data, CODE); }
void encrypt() { SHA256((const unsigned char*)base.c_str(), base.size(), hash); }
std::string challenge() const { return encode(hash, SHA256_DIGEST_LENGTH); }
void decode();
std::string urlEncode(const std::string&);
friend std::ostream& operator<<(std::ostream&s, const Code&);
};