예제 #1
0
파일: RSATest.cpp 프로젝트: as2120/ZPoco
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);
    }
}
예제 #2
0
파일: CryptoTest.cpp 프로젝트: 12307/poco
void CryptoTest::testEncryptDecryptWithSalt()
{
	Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
	Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
	
	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 = pCipher2->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 = pCipher2->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 = pCipher2->decryptString(out, Cipher::ENC_BINHEX);
		assert (in == result);
	}
}
예제 #3
0
파일: CryptoTest.cpp 프로젝트: 12307/poco
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);
}
예제 #4
0
파일: RSATest.cpp 프로젝트: as2120/ZPoco
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);
    }
}
예제 #5
0
파일: RSATest.cpp 프로젝트: as2120/ZPoco
void RSATest::testCertificate()
{
    std::istringstream str(anyPem);
    X509Certificate cert(str);
    RSAKey publicKey(cert);
    std::istringstream str2(anyPem);
    RSAKey privateKey(0, &str2, "test");
    Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(publicKey);
    Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(privateKey);
    std::string val("lets do some encryption");

    std::string enc = pCipher->encryptString(val);
    std::string dec = pCipher2->decryptString(enc);
    assert (dec == val);
}
예제 #6
0
파일: CryptoTest.cpp 프로젝트: 12307/poco
void CryptoTest::testEncryptDecryptDESECB()
{
	Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("des-ecb", "password"));

	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);
	}
}