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


C++ CryptoPP类代码示例

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


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

示例1: HASH224_message

int HASH224_message(char* message, int len, 
				char* hash_message, int hash_len)
{
	AutoSeededRandomPool prng;
	
	SecByteBlock key(16);
	prng.GenerateBlock(key, key.size());

	string plain;
	CharToString(plain, message, len);
	string mac, encoded;

	encoded.clear();
	StringSource(key, key.size(), true,
					new HexEncoder(
					new StringSink(encoded)
					)
				); //StringSource

	try
	{
		HMAC<SHA224> hmac(key, key.size());

		StringSource(plain, true, 
			new HashFilter(hmac, 
			new StringSink(mac)
			)
			);
	}
	catch(const CryptoPP::Exception& e)
	{
		cerr<<e.what()<<endl;
		return 0;
		exit(1);
	}

	encoded.clear();
	StringSource(mac, true, 
			new HexEncoder(
			new StringSink(encoded)
			)
			);

	if(hash_len <= encoded.length())
		return -1;
	StringToChar(encoded, hash_message);
	return (int)encoded.length();
}
开发者ID:Julianshang,项目名称:wave,代码行数:48,代码来源:crypto_interface.cpp

示例2: signature_verify

void signature_verify( const string & account_num, string & signature){
  
  RSA::PublicKey publicKey;
  string recovered, message;
  
  // Load public key
  CryptoPP::ByteQueue bytes;
  FileSource file("pubkey.txt", true, new Base64Decoder);
  file.TransferTo(bytes);
  bytes.MessageEnd();
  publicKey.Load(bytes);
  
  // Verify and Recover
  RSASS<PSSR, SHA1>::Verifier verifier(publicKey);
  
  StringSource(signature, true,
               new SignatureVerificationFilter(
                                               verifier,
                                               new StringSink(recovered),
                                               SignatureVerificationFilter::THROW_EXCEPTION |
                                               SignatureVerificationFilter::PUT_MESSAGE
                                               ) // SignatureVerificationFilter
               ); // StringSource
  
  assert(account_num == recovered);
  cout << "Verified signature on message" << endl;
  cout << "Message: " << "'" << recovered << "'" << endl;
  
}
开发者ID:JetpackUnicorn,项目名称:ElephantParty,代码行数:29,代码来源:crypto++_authentication_TXT.cpp

示例3: signature_sign

void signature_sign(const string & account_num, string & signature){
  
  // Setup
  string message = account_num;
  RSA::PrivateKey privateKey;
  AutoSeededRandomPool rng;
  
  // Load private key
  CryptoPP::ByteQueue bytes;
  FileSource file("privkey.txt", true, new Base64Decoder);
  file.TransferTo(bytes);
  bytes.MessageEnd();
  privateKey.Load(bytes);
  
  // Sign and Encode
  RSASS<PSSR, SHA1>::Signer signer(privateKey);
  
  // StringSource
  StringSource(message, true,
               new SignerFilter(rng, signer,
                                new StringSink(signature),
                                true // putMessage
                                ) // SignerFilter
               );
  
}
开发者ID:JetpackUnicorn,项目名称:ElephantParty,代码行数:26,代码来源:crypto++_authentication_TXT.cpp

示例4: rcry_encryptInContext

unsigned int rcry_encryptInContext(string *input, string *output)
{
	if (target == RCRY_RIJNDAEL)
	{

		try
		{
			CTR_Mode<AES>::Encryption e;
			e.SetKeyWithIV(vault_key, sizeof(vault_key), context->iv);
			StringSource((*input), true,
					new StreamTransformationFilter(e,
							new StringSink((*output))));
		} catch (const CryptoPP::Exception& e)
		{
			cerr << e.what() << endl;
			return 0x44;
		}
	}
	else
	{
		cerr << "Context not implemented! Use RCRY_RIJNAEL INSTEAD!" << endl;
		return 0xFAF;
	}

	return 0;
}
开发者ID:reepass,项目名称:libreedb,代码行数:26,代码来源:rcry_wrapper.cpp

示例5: throw

std::string Encryptor::encrypt(const std::string& word)
		throw (CryptoPP::Exception) {
	std::string cipher;

	ECB_Mode<AES>::Encryption e;
	e.SetKey(key, AES_SIZE);

	// The StreamTransformationFilter adds padding
	//  as required. ECB and CBC Mode must be padded
	//  to the block size of the cipher.
	StringSource(word, true,
			new StreamTransformationFilter(e, new StringSink(cipher)) // StreamTransformationFilter
	); // StringSource

	std::string encoded;
	StringSource(cipher, true, new HexEncoder(new StringSink(encoded))); // StringSource
	return encoded;

}
开发者ID:niavok,项目名称:crypteos,代码行数:19,代码来源:Encryptor.cpp

示例6: encrypt

    QByteArray encrypt(QByteArray in) {
        byte iv[CryptoPP::AES::BLOCKSIZE];
        rnd.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE);
        QByteArray out = QByteArray((char*)iv, CryptoPP::AES::BLOCKSIZE);
        int inputSize = in.size();
        string cipher;

        CBC_Mode<AES>::Encryption aes(keyByte(), keySize(), iv);
        ArraySource((byte *)in.data(), inputSize, true, new StreamTransformationFilter(aes, new StringSink(cipher)));

        QByteArray encryptedBytes = QByteArray(cipher.c_str(), cipher.size());
        out.append(encryptedBytes);
        return out;
    }
开发者ID:CaptEmulation,项目名称:encrypted-text-editor,代码行数:14,代码来源:cryptoaes.cpp

示例7: encrypt

string RNEncryptor::encrypt(string plaintext, string password, RNCryptorSchema schemaVersion)
{
	this->configureSettings(schemaVersion);

	RNCryptorPayloadComponents components;
	components.schema = (char)schemaVersion;
	components.options = (char)this->options;
	components.salt = this->generateSalt();
	components.hmacSalt = this->generateSalt();
	components.iv = this->generateIv(this->ivLength);

	SecByteBlock key = this->generateKey(components.salt, password);

	switch (this->aesMode) {
		case MODE_CTR: {

			CTR_Mode<AES>::Encryption encryptor;
			encryptor.SetKeyWithIV((const byte *)key.data(), key.size(), (const byte *)components.iv.data());

			StringSource(plaintext, true,
				// StreamTransformationFilter adds padding as required.
				new StreamTransformationFilter(encryptor,
					new StringSink(components.ciphertext)
				)
			);

			break;
		}
		case MODE_CBC: {

			CBC_Mode<AES>::Encryption encryptor;
			encryptor.SetKeyWithIV(key.BytePtr(), key.size(), (const byte *)components.iv.data());

			StringSource(plaintext, true,
				// StreamTransformationFilter adds padding as required.
				new StreamTransformationFilter(encryptor,
					new StringSink(components.ciphertext)
				)
			);

			break;
		}
	}

	stringstream binaryData;
	binaryData << components.schema;
	binaryData << components.options;
	binaryData << components.salt;
	binaryData << components.hmacSalt;
	binaryData << components.iv;
	binaryData << components.ciphertext;

	std::cout << "Hex encoded: " << this->hex_encode(binaryData.str()) << std::endl;

	binaryData << this->generateHmac(components, password);

	return this->base64_encode(binaryData.str());
}
开发者ID:backviet01,项目名称:RNCryptor-cpp,代码行数:58,代码来源:rnencryptor.cpp

示例8: Encrypt

QString QuizDatabase::Encrypt(QString src)
{
    QString t_output;
    byte key[AES::DEFAULT_KEYLENGTH] = EncryptionKey;
    byte iv[AES::BLOCKSIZE] = EncryptionKey_2;
    OFB_Mode<AES>::Encryption t_Encrypt;
    t_Encrypt.SetKeyWithIV(key,sizeof(key),iv);
    string t_Str,t_strNonHex,t_strCompletelyEncrypted;
    t_Str = src.toStdString();
    StringSource(t_Str,true,new StreamTransformationFilter(t_Encrypt,new StringSink(t_strNonHex)));
    StringSource(t_strNonHex,true,new HexEncoder(new StringSink(t_strCompletelyEncrypted)));
    t_output = QString::fromStdString(t_strCompletelyEncrypted);
    return t_output;
}
开发者ID:9A9A,项目名称:Quiz-Programm,代码行数:14,代码来源:mainwindow.cpp

示例9: encrypt_file

void encrypt_file(string oFile, string encMode)
{
    // SecByteBlock key(AES::MAX_KEYLENGTH);
    // byte iv[ AES::BLOCKSIZE ];
   
    string ofilename = oFile;
    string outFile = oFile + ".egg";
    string efilename = outFile;   
    
    std::ifstream ifile(oFile.c_str(), 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());
   
    if(encMode == "OFB")
    {
        OFB_Mode< AES >::Encryption e1;
        e1.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
       
        StringSource( temp, true,
                        new StreamTransformationFilter( e1,
                        new FileSink( efilename.c_str() ))); 
    }
    else if(encMode == "CFB")
    {
        CFB_Mode< AES >::Encryption e1;
        e1.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );

        StringSource( temp, true,
                        new StreamTransformationFilter( e1,
                        new FileSink( efilename.c_str() ))); 
    }
    else if(encMode == "GCM")
    {
        GCM< AES >::Encryption e1;
        e1.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
       
        StringSource ss1( temp, true,
                        new AuthenticatedEncryptionFilter( e1,
                        new FileSink( efilename.c_str() )));
    }
    else
    {
        cerr << "Invalid Mode" <<endl;
    }
}
开发者ID:swhitsett,项目名称:se430,代码行数:49,代码来源:v4_CLI_fileEncrypt.cpp

示例10: main

int main(int argc, char* argv[])
{
  AutoSeededRandomPool prng;
  byte fkey[SHA256::DIGESTSIZE];
  string key_from_file, plain;
  byte key[AES::MAX_KEYLENGTH]; // 32 bytes
  string filename=argv[2];
  string share_fkey;
  FileSource(argv[1], true,
             new HexDecoder(
                            new StringSink(key_from_file))
             );
  //removing directory paths if any
  filename = filename.substr(filename.find_last_of("/")+1,filename.length());

  byte iv[AES::BLOCKSIZE]; // 16 bytes
  iv[0] = 0;
  //prng.GenerateBlock(iv, sizeof(iv));
  string temp = key_from_file+filename;
  byte digest_input[temp.length()];
  for (int i=0;i<=temp.length();i++)
    digest_input[i]=temp[i];

  SHA256().CalculateDigest(fkey, digest_input, sizeof(digest_input));


  StringSource(fkey, sizeof(fkey),true,
               new HexEncoder(
                              new StringSink(share_fkey))
               );

  cout<<"fkey to share : "<<share_fkey<<endl;

  string new_filename = filename.substr(filename.find_last_of(".")+1,filename.length()) + '.' + filename.substr(0,filename.find_last_of("."));
  byte efile[SHA256::DIGESTSIZE];
  string encoded_efile;
  byte filename_plain_input[new_filename.length()];
  for (int i=0;i<=new_filename.length();i++)
    filename_plain_input[i]=(byte)new_filename[i];

  SHA256().CalculateDigest(efile, filename_plain_input, sizeof(filename_plain_input));
  StringSource(efile, sizeof(efile), true,
               new HexEncoder(
                              new StringSink(encoded_efile)
                              ) // HexEncoder
               ); // StringSource
  cout<<"the filename on cloud server : "<<encoded_efile<<endl<<endl;
  return 0;
}
开发者ID:kuldeepcode,项目名称:Projects,代码行数:49,代码来源:authorize.cpp

示例11: encrypt_file

void encrypt_file(string oFile)
{
    // SecByteBlock key(AES::MAX_KEYLENGTH);
    // byte iv[ AES::BLOCKSIZE ];
   
    string ofilename = oFile;
    string outFile = oFile + ".egg";
    string efilename = outFile;   
    //try {
       
        /*********************************\
         \*********************************/
       
    OFB_Mode< AES >::Encryption e1;
    e1.SetKeyWithIV( key, key.size(), iv, sizeof(iv) );
   
    std::ifstream ifile(oFile.c_str(), 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( temp, true,
                    new StreamTransformationFilter( e1,
                    new FileSink( efilename.c_str() )
                    ) // StreamTransformationFilter
                    ); // StringSource
   
    /*********************************\
     \*********************************/
}
开发者ID:swhitsett,项目名称:se430,代码行数:33,代码来源:v3_OFB_fileEncrypt.cpp

示例12: convert_to_string

string convert_to_string(const private_key& priv_key) {
  string x;
  priv_key.Save(StringSink(x).Ref());
  string x_1;
  StringSource ss(x, true, new HexEncoder(new StringSink(x_1)));
  return x_1;
}
开发者ID:grubino,项目名称:trollcoin,代码行数:7,代码来源:helpers.cpp

示例13: LoadKey

void LoadKey(const string& filename, RSA::PrivateKey& PrivateKey)
{
  // DER Encode Key - PKCS #8 key format
  PrivateKey.Load(
                  FileSource(filename.c_str(), true, NULL, true /*binary*/).Ref()
                  );
}
开发者ID:JetpackUnicorn,项目名称:ElephantParty,代码行数:7,代码来源:crypto++_authentication_TXT.cpp

示例14: SaveKey

void SaveKey(const RSA::PublicKey& PublicKey, const string& filename)
{
  // DER Encode Key - X.509 key format
  PublicKey.Save(
                 FileSink(filename.c_str(), true /*binary*/).Ref()
                 );
}
开发者ID:JetpackUnicorn,项目名称:ElephantParty,代码行数:7,代码来源:crypto++_authentication_TXT.cpp

示例15: DecryptToInt

int QuizDatabase::DecryptToInt(QString &src)
{
    QString t_input;
    int lResult;
    QString temp;
    byte key[AES::DEFAULT_KEYLENGTH] = EncryptionKey;
    byte iv[AES::BLOCKSIZE] = EncryptionKey_2;
    OFB_Mode<AES>::Decryption t_Decrypt;
    t_Decrypt.SetKeyWithIV(key,sizeof(key),iv);
    string t_Str,t_strNonHex,t_strCompletelyEncrypted;
    t_strCompletelyEncrypted = src.toStdString();
    StringSource(t_strCompletelyEncrypted,true,new HexDecoder(new StringSink(t_strNonHex)));
    StringSource(t_strNonHex,true,new StreamTransformationFilter(t_Decrypt,new StringSink(t_Str)));
    t_input = QString::fromStdString(t_Str);
    lResult = t_input.toInt();
    return lResult;
}
开发者ID:9A9A,项目名称:Quiz-Programm,代码行数:17,代码来源:mainwindow.cpp


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