本文整理汇总了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;
}
示例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);
}
示例3: SetRandomValue
void CUIntX::SetRandomValue()
{
using namespace CryptoPP;
AutoSeededRandomPool rng;
rng.GenerateBlock(GetData(), GetSize());
}
示例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;
}
示例5: GenerateRandomSequence
std::string GenerateRandomSequence(size_t length) {
AutoSeededRandomPool rnd;
string result;
result.resize(length);
rnd.GenerateBlock((byte*)result.data(), length);
return result;
}
示例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) };
}
示例7:
CUInt128& CUInt128::setValueRandom(void)
{
AutoSeededRandomPool rng;
byte randomBytes[16];
rng.GenerateBlock(randomBytes, 16);
setValueBE( randomBytes );
return *this;
}
示例8:
CUInt128& CUInt128::SetValueRandom()
{
AutoSeededRandomPool rng;
byte byRandomBytes[16];
rng.GenerateBlock(byRandomBytes, 16);
SetValueBE( byRandomBytes );
return *this;
}
示例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;
}
示例10: work
void DaStorKeyGenerator::work()
{
AutoSeededRandomPool rnd;
cout << "gen key in memery." << endl;
rnd.GenerateBlock(keyData, AES::DEFAULT_KEYLENGTH);
saveKeyFile();
saveKeyCpp();
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}