当前位置: 首页>>代码示例>>C++>>正文


C++ AutoSeededRandomPool类代码示例

本文整理汇总了C++中AutoSeededRandomPool的典型用法代码示例。如果您正苦于以下问题:C++ AutoSeededRandomPool类的具体用法?C++ AutoSeededRandomPool怎么用?C++ AutoSeededRandomPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AutoSeededRandomPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: generateKeysAES

void Node::generateKeysAES(void){
	AutoSeededRandomPool rnd;
	aeskey=SecByteBlock(0x00, AES::DEFAULT_KEYLENGTH);
	rnd.GenerateBlock( aeskey, aeskey.size() );
	rnd.GenerateBlock(iv, AES::BLOCKSIZE);
	return;
}
开发者ID:brange-rutgers,项目名称:Security-Engineering-Final,代码行数:7,代码来源:Node.cpp

示例2: RandomQuadraticResidue

CryptoPP::Integer RandomQuadraticResidue(CryptoPP::Integer p) {
	AutoSeededRandomPool rng;
	byte randomBytes[64];
	rng.GenerateBlock(randomBytes, 64);
	Integer t = Integer(randomBytes, 64);
	return ModularExponentiation(t, 2, p);
}
开发者ID:rebornix,项目名称:ppdl,代码行数:7,代码来源:BackProp.cpp

示例3: SetRandomValue

void CUIntX::SetRandomValue()
{
	using namespace CryptoPP;

	AutoSeededRandomPool rng;
	rng.GenerateBlock(GetData(), GetSize());
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:7,代码来源:UIntX.cpp

示例4: DES3

    static string DES3(const string & text, const char * passwd = "", const char * stored_iv = "", const bool & encryption = true) {
        const char * enhPwd(enhancePasswd(passwd, int(DES_EDE3::DEFAULT_KEYLENGTH)));
        SecByteBlock key(strlen(enhPwd));
        byte iv[DES_EDE3::BLOCKSIZE];

        for(int i(0); i < strlen(enhPwd); ++i)
            key[i] = enhPwd[i];

        if(stored_iv == "") {
            AutoSeededRandomPool prng;
            prng.GenerateBlock(iv, sizeof(iv));
        } else
            for(int i(0); i < DES_EDE3::BLOCKSIZE; ++i)
                iv[i] = (byte)stored_iv[i];

        string cipher("");
        try {
            if(encryption) {
                CBC_Mode< DES_EDE3 >::Encryption e;
                e.SetKeyWithIV(key, key.size(), iv);
                StringSource(text, true, new StreamTransformationFilter(e, new StringSink(cipher)));
                cipher.append("\n").append((char *)iv);
            } else {
                CBC_Mode< DES_EDE3 >::Decryption d;
                d.SetKeyWithIV(key, key.size(), iv);
                StringSource(text, true, new StreamTransformationFilter(d, new StringSink(cipher)));
            }
        } catch(const CryptoPP::Exception & e) {
            cerr << e.what() << endl;
            exit(1);
        }
        return cipher;
    }
开发者ID:Adrael,项目名称:Switch,代码行数:33,代码来源:crypto.hpp

示例5: GenerateRandomSequence

std::string GenerateRandomSequence(size_t length) {
    AutoSeededRandomPool rnd;
    string result;
    result.resize(length);
    rnd.GenerateBlock((byte*)result.data(), length);
    return result;
}
开发者ID:GoBudokai,项目名称:ozifi,代码行数:7,代码来源:crypto.cpp

示例6: b

std::vector<unsigned char> ContainerController::get_pseudo_seed()
{
	using namespace CryptoPP;
	SecByteBlock b(32);
	AutoSeededRandomPool prng;
	prng.GenerateBlock(b, b.size());
	return{ std::begin(b), std::end(b) };
}
开发者ID:KaiSta,项目名称:scrates,代码行数:8,代码来源:ContainerController.cpp

示例7:

CUInt128& CUInt128::setValueRandom(void)
{
	AutoSeededRandomPool rng;
	byte randomBytes[16];
	rng.GenerateBlock(randomBytes, 16);
	setValueBE( randomBytes );
	return *this;
}
开发者ID:machado2,项目名称:emule,代码行数:8,代码来源:UInt128.cpp

示例8:

CUInt128& CUInt128::SetValueRandom()
{
	AutoSeededRandomPool rng;
	byte byRandomBytes[16];
	rng.GenerateBlock(byRandomBytes, 16);
	SetValueBE( byRandomBytes );
	return *this;
}
开发者ID:LjApps,项目名称:eMule-VeryCD,代码行数:8,代码来源:UInt128.cpp

示例9: main

int main(int argc, char* argv[])
{
    (void)argc; (void)argv;
   
    AutoSeededRandomPool prng;
   
    SecByteBlock key(Blowfish::DEFAULT_KEYLENGTH);
    prng.GenerateBlock( key, key.size() );
   
    byte iv[ Blowfish::BLOCKSIZE ];
    prng.GenerateBlock( iv, sizeof(iv) );
   
    string ofilename = "puppy-and-teddy-orig.jpg";
    string efilename = "puppy-and-teddy.enc";
    string rfilename = "puppy-and-teddy-recovered.jpg";
   
    try {
       
        /*********************************\
         \*********************************/
       
    EAX< Blowfish >::Encryption e1;
    e1.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
   
    std::ifstream ifile("puppy-and-teddy-orig.jpg", ios::binary);
    std::ifstream::pos_type size = ifile.seekg(0, std::ios_base::end).tellg();
    ifile.seekg(0, std::ios_base::beg);
   
    string temp;
    temp.resize(size);
    ifile.read((char*)temp.data(), temp.size());
   
    StringSource ss1( temp, true,
                     new AuthenticatedEncryptionFilter( e1,
                                                       new FileSink( efilename.c_str() )
                                                       ) // StreamTransformationFilter
                     ); // StringSource
   
    /*********************************\
     \*********************************/
   
    EAX< Blowfish >::Decryption d2;
    d2.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
   
    FileSource fs2( efilename.c_str(), true,
                     new AuthenticatedDecryptionFilter( d2,
                                                       new FileSink( rfilename.c_str() ),
                                                       AuthenticatedDecryptionFilter::THROW_EXCEPTION
                                                       ) // StreamTransformationFilter
                     ); // StringSource
       
       
    } catch (const Exception& ex) {
        cerr << ex.what() << endl;
    }
   
    return 0;
}
开发者ID:swhitsett,项目名称:se430,代码行数:58,代码来源:narp.cpp

示例10: work

void DaStorKeyGenerator::work()
{
    AutoSeededRandomPool rnd;

    cout << "gen key in memery." << endl;
    rnd.GenerateBlock(keyData, AES::DEFAULT_KEYLENGTH);
    saveKeyFile();
    saveKeyCpp();
}
开发者ID:schubertzhang,项目名称:dastor,代码行数:9,代码来源:DaStorKeyGenerator.cpp

示例11: srand

bool CWSKey::Save(char *filename)
{
    int version = WSK_VERSION;
    char junk1[1234] = {0};
    char junk2[3456] = {0};
    char encrypt[sizeof(junk1)+sizeof(WSKey_key)+sizeof(junk2)] = {0};
    FILE *file = 0;

    // Set Seed Value
    srand(GetTickCount());  // set Seed Value for Pseudo Random Number Generator

    // Generate Junk Data
    for (int x = 0; x < sizeof(junk1); x++) {
        junk1[x] = (char) (-127 + (rand( ) % 127));
        junk2[x] = (char) (-127 + (rand( ) % 127));
    }
    for (int x = sizeof(junk1); x < sizeof(junk2); x++) {
        junk2[x] = (char) (0 + (rand( ) % 255));
    }

    // Encrypt ALL DATA BEFORE WRITE
    AutoSeededRandomPool rnd;
    // Generate a random key
    byte key[AES::DEFAULT_KEYLENGTH];
    rnd.GenerateBlock(key, AES::DEFAULT_KEYLENGTH);
    // Generate a random IV
    byte iv[AES::BLOCKSIZE];
    rnd.GenerateBlock(iv, AES::BLOCKSIZE);
    // Copy To Tmp Place, Then Encrypt
    WSKey_key encrypt_key = this->m_key;
    CFB_Mode<AES>::Encryption cfbEncryption(key, AES::DEFAULT_KEYLENGTH, iv);
    cfbEncryption.ProcessData((byte*)junk1, (byte*)junk1, sizeof(junk1));
    cfbEncryption.ProcessData((byte*)&encrypt_key, (byte*)&encrypt_key, sizeof(m_key));
    cfbEncryption.ProcessData((byte*)junk2, (byte*)junk2, sizeof(junk2));

    // Write Key File
    file = fopen(filename, "wb");
    if (file == 0) {
        WSK_LOG("Failed To Open The Key File");
        return false;
    }

    // Write Encrypted Key Data
    fwrite(&version, sizeof(version), 1, file);             // File Version
    fwrite(junk1, sizeof(junk1), 1, file);                  // write junk
    fwrite(&encrypt_key, sizeof(m_key), 1, file);   // Write Key
//	fwrite(&m_key, sizeof(m_key), 1, file);			// Unencrypted Key
    fwrite(key, sizeof(key), 1, file);                              // AES KEY
    fwrite(iv, sizeof(iv), 1, file);                                // AES iv
    fwrite(junk2, sizeof(junk2), 1, file);                  // write junk

    // Close file
    fclose(file);

    return true;
}
开发者ID:starboarder2001,项目名称:paintballfieldbuilder,代码行数:56,代码来源:wskey.cpp

示例12: main

int main(){
	AutoSeededRandomPool rand;
	SecByteBlock key(AES::DEFAULT_KEYLENGTH);
	rand.GenerateBlock(key, key.size());

	byte iv[AES::BLOCKSIZE];
	rand.GenerateBlock(iv, sizeof(iv));

	encryptFile("test.txt", key, iv);
	decryptFile("encText.txt", key, iv);
}
开发者ID:tincan24,项目名称:Ciphers,代码行数:11,代码来源:cryptFile.cpp

示例13: genAESParams

AESParams genAESParams(){
  AESParams params;
  AutoSeededRandomPool rnd;
  SecByteBlock key(0x00, AES::DEFAULT_KEYLENGTH);
  SecByteBlock iv(0x00, AES::BLOCKSIZE);
  rnd.GenerateBlock(iv, AES::BLOCKSIZE);
  rnd.GenerateBlock(key, AES::DEFAULT_KEYLENGTH);  
  params.key = key;
  params.iv = iv;
  return params;
}
开发者ID:ssr341,项目名称:Cryptography-Cloud-Storage,代码行数:11,代码来源:utility.cpp

示例14: generateIv

string RNEncryptor::generateIv(int length)
{
	AutoSeededRandomPool prng;

	byte iv[length + 1];
	prng.GenerateBlock(iv, length);

        iv[length] = '\0';

	string ivString = string((char *)iv);
	return ivString;
}
开发者ID:backviet01,项目名称:RNCryptor-cpp,代码行数:12,代码来源:rnencryptor.cpp

示例15: GenerateKey

void MyAES::GenerateKey()
{
    AutoSeededRandomPool rnd;
    byte key1[AES::DEFAULT_KEYLENGTH];
    rnd.GenerateBlock(key1, AES::DEFAULT_KEYLENGTH);

    // Generate a random IV
    byte iv1[AES::BLOCKSIZE];
    rnd.GenerateBlock(iv1, AES::BLOCKSIZE);

    SetKey(key1, iv1, 16);
}
开发者ID:liuyueyi,项目名称:Graduation,代码行数:12,代码来源:MyAES.cpp


注:本文中的AutoSeededRandomPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。