documentation for PICrypt

git-svn-id: svn://db.shs.com.ru/pip@102 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-15 14:23:00 +00:00
parent 85d90729fa
commit 9435ef726b
4 changed files with 59 additions and 9 deletions

View File

@@ -21,6 +21,8 @@
#ifdef PIP_CRYPT
# include "sodium.h"
#endif
const char hash_def_key[] = "_picrypt_";
@@ -144,6 +146,17 @@ PIByteArray PICrypt::hash(const PIString & secret) {
}
PIByteArray PICrypt::generateKey() {
PIByteArray hash;
#ifdef PIP_CRYPT
sodium_init();
hash.resize(crypto_secretbox_KEYBYTES);
randombytes_buf(hash.data(), hash.size());
#endif
return hash;
}
int PICrypt::sizeKey() {
#ifdef PIP_CRYPT
return crypto_secretbox_KEYBYTES;

View File

@@ -27,18 +27,40 @@
class PICrypt {
public:
//! Construct and generate random key
PICrypt();
//! Set key to "key", key size must be a \a sizeKey()
bool setKey(const PIByteArray & key);
//! Generate and set key from keyphrase "secret"
PIByteArray setKey(const PIString & secret);
//! Returns current key
PIByteArray key() {return key_;}
//! Encrypt given data "data", result size will be increased by \a sizeCrypt()
PIByteArray crypt(const PIByteArray & data);
//! Decrypt given data "crypt_data"
PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0);
//! Encrypt given data "data" with key "key", result size will be increased by \a sizeCrypt()
static PIByteArray crypt(const PIByteArray & data, const PIByteArray & key);
//! Decrypt given data "crypt_data" with key "key"
static PIByteArray decrypt(const PIByteArray & crypt_data, const PIByteArray & key, bool * ok = 0);
//! Generate hash from keyphrase "secret", may be used as a key for encryption
static PIByteArray hash(const PIString & secret);
//! Generate random key
static PIByteArray generateKey();
//! Returns key size
static int sizeKey();
//! Returns size which be added to data size in encryption process
static int sizeCrypt();
private: