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