本文整理汇总了C++中SymmetricKey::setKeyBits方法的典型用法代码示例。如果您正苦于以下问题:C++ SymmetricKey::setKeyBits方法的具体用法?C++ SymmetricKey::setKeyBits怎么用?C++ SymmetricKey::setKeyBits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymmetricKey
的用法示例。
在下文中一共展示了SymmetricKey::setKeyBits方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateKey
bool OSSLDES::generateKey(SymmetricKey& key, RNG* rng /* = NULL */)
{
if (rng == NULL)
{
return false;
}
if (key.getBitLen() == 0)
{
return false;
}
ByteString keyBits;
// don't count parity bit
if (!rng->generateRandom(keyBits, key.getBitLen()/7))
{
return false;
}
// fix the odd parity
size_t i;
for (i = 0; i < keyBits.size(); i++)
{
keyBits[i] = odd_parity[keyBits[i]];
}
return key.setKeyBits(keyBits);
}
示例2: testHmac
void GOSTTests::testHmac()
{
// Get an RNG and HMAC GOST R34.11-94 instance
CPPUNIT_ASSERT((rng = CryptoFactory::i()->getRNG()) != NULL);
CPPUNIT_ASSERT((mac = CryptoFactory::i()->getMacAlgorithm("hmac-gost")) != NULL);
// Key
char pk[] = "a_key_for_HMAC-GOST_R-34.11-94_test";
ByteString k((unsigned char *)pk, sizeof(pk));
SymmetricKey key;
CPPUNIT_ASSERT(key.setKeyBits(k));
// Generate some random input data
ByteString b;
CPPUNIT_ASSERT(rng->generateRandom(b, 53287));
// Sign the MAC using our implementation in a single operation
ByteString mResult1;
CPPUNIT_ASSERT(mac->signInit(&key));
CPPUNIT_ASSERT(mac->signUpdate(b));
CPPUNIT_ASSERT(mac->signFinal(mResult1));
// Sign the MAC in a multiple part operation
ByteString mResult2;
CPPUNIT_ASSERT(mac->signInit(&key));
CPPUNIT_ASSERT(mac->signUpdate(b.substr(0, 567)));
CPPUNIT_ASSERT(mac->signUpdate(b.substr(567, 989)));
CPPUNIT_ASSERT(mac->signUpdate(b.substr(567 + 989)));
CPPUNIT_ASSERT(mac->signFinal(mResult2));
// Now verify the MAC using our implementation in a single operation
CPPUNIT_ASSERT(mac->verifyInit(&key));
CPPUNIT_ASSERT(mac->verifyUpdate(b));
CPPUNIT_ASSERT(mac->verifyFinal(mResult2));
// Now verify the MAC in a multiple part operation
CPPUNIT_ASSERT(mac->verifyInit(&key));
CPPUNIT_ASSERT(mac->verifyUpdate(b.substr(0, 567)));
CPPUNIT_ASSERT(mac->verifyUpdate(b.substr(567, 989)));
CPPUNIT_ASSERT(mac->verifyUpdate(b.substr(567 + 989)));
CPPUNIT_ASSERT(mac->verifyFinal(mResult1));
// Check if bad key is refused
mResult1[10] ^= 0x11;
CPPUNIT_ASSERT(mac->verifyInit(&key));
CPPUNIT_ASSERT(mac->verifyUpdate(b));
CPPUNIT_ASSERT(!mac->verifyFinal(mResult1));
CryptoFactory::i()->recycleMacAlgorithm(mac);
mac = NULL;
rng = NULL;
}
示例3: generateKey
bool SymmetricAlgorithm::generateKey(SymmetricKey& key, RNG* rng /* = NULL */)
{
if (rng == NULL)
{
return false;
}
if (key.getBitLen() == 0)
{
return false;
}
ByteString keyBits;
if (!rng->generateRandom(keyBits, key.getBitLen()/8))
{
return false;
}
return key.setKeyBits(keyBits);
}
示例4: reconstructKey
bool SymmetricAlgorithm::reconstructKey(SymmetricKey& key, const ByteString& serialisedData)
{
return key.setKeyBits(serialisedData);
}