本文整理汇总了C++中Library::CreatePrivateKey方法的典型用法代码示例。如果您正苦于以下问题:C++ Library::CreatePrivateKey方法的具体用法?C++ Library::CreatePrivateKey怎么用?C++ Library::CreatePrivateKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library
的用法示例。
在下文中一共展示了Library::CreatePrivateKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShufflePrimitivesTest
void ShufflePrimitivesTest(OnionEncryptor &oe)
{
int count = Random::GetInstance().GetInt(10, 20);
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QVector<QSharedPointer<AsymmetricKey> > private_keys;
QVector<QSharedPointer<AsymmetricKey> > public_keys;
for(int idx = 0; idx < count; idx++) {
private_keys.append(QSharedPointer<AsymmetricKey>(lib->CreatePrivateKey()));
public_keys.append(QSharedPointer<AsymmetricKey>(private_keys.last()->GetPublicKey()));
}
QVector<QByteArray> cleartexts;
QVector<QByteArray> ciphertexts;
QVector<QVector<QByteArray> > random_bits;
QScopedPointer<Random> rand(lib->GetRandomNumberGenerator());
for(int idx = 0; idx < count; idx++) {
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
QByteArray ciphertext;
QVector<QByteArray> random;
EXPECT_EQ(oe.Encrypt(public_keys, cleartext, ciphertext, &random), -1);
cleartexts.append(cleartext);
ciphertexts.append(ciphertext);
random_bits.append(random);
}
QVector<QVector<QByteArray> > order_random_bits;
EXPECT_EQ(oe.ReorderRandomBits(random_bits, order_random_bits), -1);
EXPECT_TRUE(oe.VerifyOne(private_keys.first(), cleartexts,
order_random_bits.first()));
for(int idx = 1; idx < count - 1; idx++) {
EXPECT_TRUE(oe.VerifyOne(private_keys[idx], order_random_bits[idx - 1],
order_random_bits[idx]));
}
EXPECT_TRUE(oe.VerifyOne(private_keys.last(), order_random_bits.last(),
ciphertexts));
QVector<QVector<QByteArray> > onions(count + 1);
onions.last() = ciphertexts;
for(int idx = count - 1; idx >= 0; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
QBitArray bad;
EXPECT_TRUE(oe.VerifyAll(private_keys, onions, bad));
for(int idx = 0; idx < count; idx++) {
EXPECT_TRUE(onions.first().contains(cleartexts[idx]));
EXPECT_FALSE(bad[idx]);
}
}
示例2: PublicKeySwapTest
void PublicKeySwapTest(OnionEncryptor &oe)
{
int count = Random::GetInstance().GetInt(10, 20);
int changed = Random::GetInstance().GetInt(0, count);
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QVector<QSharedPointer<AsymmetricKey> > private_keys;
QVector<QSharedPointer<AsymmetricKey> > public_keys;
for(int idx = 0; idx < count; idx++) {
private_keys.append(QSharedPointer<AsymmetricKey>(lib->CreatePrivateKey()));
public_keys.append(QSharedPointer<AsymmetricKey>(private_keys.last()->GetPublicKey()));
}
private_keys[changed] = QSharedPointer<AsymmetricKey>(lib->CreatePrivateKey());
QVector<QByteArray> cleartexts;
QVector<QByteArray> ciphertexts;
QScopedPointer<Random> rand(lib->GetRandomNumberGenerator());
for(int idx = 0; idx < count; idx++) {
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
QByteArray ciphertext;
EXPECT_EQ(oe.Encrypt(public_keys, cleartext, ciphertext, 0), -1);
cleartexts.append(cleartext);
ciphertexts.append(ciphertext);
}
QVector<QVector<QByteArray> > onions(count + 1);
onions.last() = ciphertexts;
for(int idx = count - 1; idx > changed; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx],onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
EXPECT_FALSE(oe.Decrypt(private_keys[changed], onions[changed + 1], onions[changed], 0));
}
示例3: PrepareForChallenge
QVariant LRSAuthenticate::PrepareForChallenge()
{
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QSharedPointer<AsymmetricKey> skey(lib->CreatePrivateKey());
QSharedPointer<AsymmetricKey> dkey(lib->CreatePrivateKey());
QSharedPointer<DiffieHellman> dh(lib->CreateDiffieHellman());
_ident = PrivateIdentity(_ori_ident.GetLocalId(), skey, dkey, dh,
_ori_ident.GetSuperPeer());
_pub_ident = GetPublicIdentity(_ident);
QByteArray bident;
QDataStream stream(&bident, QIODevice::WriteOnly);
stream << _pub_ident;
QVariantList list;
list.append(bident);
list.append(_lrs->Sign(bident));
return list;
}
示例4: OnionEncryptorDecrypt
void OnionEncryptorDecrypt(OnionEncryptor &oe)
{
int count = 100;
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QVector<QSharedPointer<AsymmetricKey> > private_keys;
QVector<QSharedPointer<AsymmetricKey> > public_keys;
for(int idx = 0; idx < count; idx++) {
private_keys.append(QSharedPointer<AsymmetricKey>(lib->CreatePrivateKey()));
public_keys.append(QSharedPointer<AsymmetricKey>(private_keys.last()->GetPublicKey()));
}
QVector<QByteArray> cleartexts;
QVector<QByteArray> ciphertexts;
QScopedPointer<Random> rand(lib->GetRandomNumberGenerator());
for(int idx = 0; idx < count; idx++) {
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
QByteArray ciphertext;
EXPECT_EQ(oe.Encrypt(public_keys, cleartext, ciphertext), -1);
cleartexts.append(cleartext);
ciphertexts.append(ciphertext);
}
QVector<QVector<QByteArray> > onions(count + 1);
onions.last() = ciphertexts;
QVector<QVector<QByteArray> > oonions(count + 1);
oonions.last() = ciphertexts;
for(int idx = count - 1; idx >= 0; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx]));
}
for(int idx = 0; idx < count; idx++) {
EXPECT_TRUE(onions.first().contains(cleartexts[idx]));
}
}
示例5: SoMuchEvil
void SoMuchEvil(OnionEncryptor &oe)
{
int count = Random::GetInstance().GetInt(10, 20);
int changed0 = Random::GetInstance().GetInt(0, count - 5);
int changed1 = Random::GetInstance().GetInt(changed0 + 1, count + 1);
int mchanged0 = Random::GetInstance().GetInt(0, count);
int mchanged1 = Random::GetInstance().GetInt(0, count);
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QVector<QSharedPointer<AsymmetricKey> > private_keys;
QVector<QSharedPointer<AsymmetricKey> > public_keys;
for(int idx = 0; idx < count; idx++) {
private_keys.append(QSharedPointer<AsymmetricKey>(lib->CreatePrivateKey()));
public_keys.append(QSharedPointer<AsymmetricKey>(private_keys.last()->GetPublicKey()));
}
QVector<QByteArray> cleartexts;
QVector<QByteArray> ciphertexts;
QScopedPointer<Random> rand(lib->GetRandomNumberGenerator());
for(int idx = 0; idx < count; idx++) {
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
QByteArray ciphertext;
EXPECT_EQ(oe.Encrypt(public_keys, cleartext, ciphertext, 0), -1);
cleartexts.append(cleartext);
ciphertexts.append(ciphertext);
}
QVector<QVector<QByteArray> > onions(count + 1);
onions.last() = ciphertexts;
// Find first evil peer
for(int idx = count - 1; idx >= changed1; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
QVector<QSharedPointer<AsymmetricKey> > swap_keys(public_keys);
swap_keys.resize(changed1);
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
EXPECT_EQ(oe.Encrypt(swap_keys, cleartext, onions[changed1][mchanged1], 0), -1);
// Find second evil peer
for(int idx = changed1 - 1; idx >= changed0; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
swap_keys.resize(changed0);
rand->GenerateBlock(cleartext);
EXPECT_EQ(oe.Encrypt(swap_keys, cleartext, onions[changed0][mchanged0], 0), -1);
for(int idx = changed0 - 1; idx >= 0; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
QBitArray bad;
EXPECT_FALSE(oe.VerifyAll(private_keys, onions, bad));
int good_count = 0;
int bad_count = 0;
for(int idx = 0; idx < count; idx++) {
if(idx == changed0 || idx == changed1) {
EXPECT_TRUE(bad[idx]);
} else {
EXPECT_FALSE(bad[idx]);
}
onions.first().contains(cleartexts[idx]) ? good_count++ : bad_count++;
}
EXPECT_TRUE(good_count >= count - 2);
EXPECT_TRUE(good_count < count);
EXPECT_TRUE(bad_count > 0);
EXPECT_TRUE(bad_count <= 2);
}