documentation for PICrypt
git-svn-id: svn://db.shs.com.ru/pip@102 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user