This class aim is to minimize encryption output.
More...
#include <VirgilTinyCipher.h>
|
|
| VirgilTinyCipher (size_t packageSize=PackageSize_Short_SMS) |
| Init cipher with given maximum package size. More...
|
|
void | reset () |
| Prepare cipher for the next encryption. More...
|
|
virtual | ~VirgilTinyCipher () throw () |
| Destroy pimpl class object.
|
|
|
void | encrypt (const VirgilByteArray &data, const VirgilByteArray &recipientPublicKey) |
| Encrypt data with given public key. More...
|
|
void | encryptAndSign (const VirgilByteArray &data, const VirgilByteArray &recipientPublicKey, const VirgilByteArray &senderPrivateKey, const VirgilByteArray &senderPrivateKeyPassword=VirgilByteArray()) |
| Encrypt data with given public key and sign package. More...
|
|
size_t | getPackageCount () const |
| Return total package count. More...
|
|
VirgilByteArray | getPackage (size_t index) const |
| Return specific package. More...
|
|
|
void | addPackage (const VirgilByteArray &package) |
| Add package. More...
|
|
bool | isPackagesAccumulated () const |
| Define whether all packages was accumulated or not. More...
|
|
VirgilByteArray | decrypt (const VirgilByteArray &recipientPrivateKey, const VirgilByteArray &recipientPrivateKeyPassword=VirgilByteArray()) |
| Decrypt accumulated packages. More...
|
|
VirgilByteArray | verifyAndDecrypt (const VirgilByteArray &senderPublicKey, const VirgilByteArray &recipientPrivateKey, const VirgilByteArray &recipientPrivateKeyPassword=VirgilByteArray()) |
| Verify accumulated packages and then decrypt it. More...
|
|
This class aim is to minimize encryption output.
- Motivation
- If encrypted data is transmitted over GSM module, it very important that encryption output was as small as possible.
- Solution
- Throw out crypto agility and transfer minimum public information required for decryption.
- Pros
-
- Cons
- Crypto agility is not included in the message, so encrypted messages should not be stored for long term.
- Details
- During encryption ciper packs encrypted message and service information to the set of packages, which length is limited by maximim package length.
- Restrictions
- Currently supported public/private keys:
- Minimum package length:
- See also
- VirgilTinyCipher(size_t packageSize)
-
VirgilTinyCipher::PackageSize
- Example - Encrypt
tinyCipher.encrypt(data, recipientPublicKey);
for (size_t i = 0; i < tinyCipher.getPackageCount(); ++i) {
VirgilByteArray package = tinyCipher.getPackage(i);
}
- Example - Encrypt and Sign
tinyCipher.encryptAndSign(data, recipientPublicKey, senderPrivateKey, senderPrivateKeyPassword);
for (size_t i = 0; i < tinyCipher.getPackageCount(); ++i) {
VirgilByteArray package = tinyCipher.getPackage(i);
}
- Example - Decrypt
tinyCipher.addPackage(receivedPackage);
if (tinyCipher.isPackagesAccumulated()) {
decryptedData = tinyCipher.decrypt(recipientPrivateKey, recipientPrivateKeyPassword);
}
- Example - Verify and Decrypt
tinyCipher.addPackage(receivedPackage);
if (tinyCipher.isPackagesAccumulated()) {
decryptedData = tinyCipher.verifyAndDecrypt(senderPublicKey, recipientPrivateKey, recipientPrivateKeyPassword);
}
Constants that represents maximum number of bytes in one package.
- Note
- Text representation is 4/3 bigger, i.e 120 * 4/3 = 160 - for short sms.
Enumerator |
---|
PackageSize_Min |
Min.
|
PackageSize_Short_SMS |
Short SMS.
|
PackageSize_Long_SMS |
Long SMS.
|
Init cipher with given maximum package size.
- Parameters
-
packageSize | - maximum number of bytes in one package |
- Exceptions
-
std::logic_error | - if given packageSize less then minimum value |
- See also
- VirgilTinyCipher::PackageSize
void virgil::crypto::VirgilTinyCipher::addPackage |
( |
const VirgilByteArray & |
package | ) |
|
Add package.
Accumulate packages before decryption.
- Parameters
-
package | - package to be accumulated |
- See also
- To determine that all packages are received call function isPackagesAccumulated().
- Exceptions
-
VirgilByteArray virgil::crypto::VirgilTinyCipher::decrypt |
( |
const VirgilByteArray & |
recipientPrivateKey, |
|
|
const VirgilByteArray & |
recipientPrivateKeyPassword = VirgilByteArray() |
|
) |
| |
Decrypt accumulated packages.
- Parameters
-
recipientPrivateKey | - recipient private key |
recipientPrivateKeyPassword | - recipient private key password (optional) |
- Returns
- Decrypted data.
- Exceptions
-
void virgil::crypto::VirgilTinyCipher::encrypt |
( |
const VirgilByteArray & |
data, |
|
|
const VirgilByteArray & |
recipientPublicKey |
|
) |
| |
Encrypt data with given public key.
- Parameters
-
data | - data to be encrypted |
recipientPublicKey | - recipient public key |
- See also
- getPackage()
- Exceptions
-
void virgil::crypto::VirgilTinyCipher::encryptAndSign |
( |
const VirgilByteArray & |
data, |
|
|
const VirgilByteArray & |
recipientPublicKey, |
|
|
const VirgilByteArray & |
senderPrivateKey, |
|
|
const VirgilByteArray & |
senderPrivateKeyPassword = VirgilByteArray() |
|
) |
| |
Encrypt data with given public key and sign package.
- Parameters
-
data | - data to be encrypted |
recipientPublicKey | - recipient public key |
senderPrivateKey | - sender private key |
senderPrivateKeyPassword | - sender private key password (optional) |
- See also
- Related links can be found in the encrypt() function description.
- Exceptions
-
VirgilByteArray virgil::crypto::VirgilTinyCipher::getPackage |
( |
size_t |
index | ) |
const |
Return specific package.
Return package with specific index.
- Parameters
-
- Note
- Packages are available when encryption process is completed.
- Exceptions
-
std::out_of_range | - if package with given index is not exists |
size_t virgil::crypto::VirgilTinyCipher::getPackageCount |
( |
| ) |
const |
Return total package count.
- Note
- Package count is known when encryption process is completed.
- See also
- getPackage()
bool virgil::crypto::VirgilTinyCipher::isPackagesAccumulated |
( |
| ) |
const |
Define whether all packages was accumulated or not.
- Returns
- true - if all packages was successfully accumulated, false otherwise
- See also
- addPackage()
void virgil::crypto::VirgilTinyCipher::reset |
( |
| ) |
|
Prepare cipher for the next encryption.
- Note
- SHOULD be used before the next encryption.
VirgilByteArray virgil::crypto::VirgilTinyCipher::verifyAndDecrypt |
( |
const VirgilByteArray & |
senderPublicKey, |
|
|
const VirgilByteArray & |
recipientPrivateKey, |
|
|
const VirgilByteArray & |
recipientPrivateKeyPassword = VirgilByteArray() |
|
) |
| |
Verify accumulated packages and then decrypt it.
- Parameters
-
senderPublicKey | - sender public key |
recipientPrivateKey | - recipient private key |
recipientPrivateKeyPassword | - recipient private key password (optional) |
- Exceptions
-
The documentation for this class was generated from the following file: