Example #1
0
void CryptoTest::testEncryptDecrypt()
{
	Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));

	for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
	{
		std::string in(n, 'x');
		std::string out = pCipher->encryptString(in, Cipher::ENC_NONE);
		std::string result = pCipher->decryptString(out, Cipher::ENC_NONE);
		assert (in == result);
	}

	for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
	{
		std::string in(n, 'x');
		std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
		std::string result = pCipher->decryptString(out, Cipher::ENC_BASE64);
		assert (in == result);
	}

	for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
	{
		std::string in(n, 'x');
		std::string out = pCipher->encryptString(in, Cipher::ENC_BINHEX);
		std::string result = pCipher->decryptString(out, Cipher::ENC_BINHEX);
		assert (in == result);
	}
}
Example #2
0
void RSATest::testRSACipherLarge()
{
    std::vector<std::size_t> sizes;
    sizes.push_back (2047);
    sizes.push_back (2048);
    sizes.push_back (2049);
    sizes.push_back (4095);
    sizes.push_back (4096);
    sizes.push_back (4097);
    sizes.push_back (8191);
    sizes.push_back (8192);
    sizes.push_back (8193);
    sizes.push_back (16383);
    sizes.push_back (16384);
    sizes.push_back (16385);

    Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
    for (std::vector<std::size_t>::const_iterator it = sizes.begin(); it != sizes.end(); ++it)
    {
        std::string val(*it, 'x');
        std::string enc = pCipher->encryptString(val);
        std::string dec = pCipher->decryptString(enc);
        assert (dec == val);
    }
}
Example #3
0
void CryptoTest::testDecryptInterop()
{
	Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "password", "salt"));

	const std::string expectedPlainText  = "This is a secret message.";
	const std::string cipherText = "9HITTPaU3A/LaZzldbdnRZ109DKlshouKren/n8BsHc=";
	std::string plainText = pCipher->decryptString(cipherText, Cipher::ENC_BASE64);
	assert (plainText == expectedPlainText);
}
Example #4
0
void RSATest::testRSACipher()
{
    Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
    for (std::size_t n = 1; n <= 1200; n++)
    {
        std::string val(n, 'x');
        std::string enc = pCipher->encryptString(val);
        std::string dec = pCipher->decryptString(enc);
        assert (dec == val);
    }
}