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


C++ rsa::PublicKey类代码示例

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


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

示例1: 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

示例2: printPublicKey

   static void printPublicKey(RSA::PublicKey key)
   {
      ///////////////////////////////////////
      // Generated Parameters
      const Integer& n = key.GetModulus();
      const Integer& e = key.GetPublicExponent();

      cout << "RSA Parameters:" << endl;
      cout << " n: " << n << endl;
      cout << " e: " << e << endl;
      cout << endl;

   }
开发者ID:babenkoav78,项目名称:iviLink,代码行数:13,代码来源:CRSAEncryptDecrypt.hpp

示例3: DecodeFromFile

static bool DecodeFromFile(const char* filename, RSA::PublicKey& key)
{
	try {
		ByteQueue queue;
		FileSource file(filename, true);
		file.TransferTo(queue);
		queue.MessageEnd();
		key.BERDecodePublicKey(queue, false, queue.MaxRetrievable());
		return key.Validate(rng, 3);
	} catch (...) {
		return false;
	}
}
开发者ID:vshymanskyy,项目名称:kad,代码行数:13,代码来源:signtool.cpp

示例4: loadRSAPubKey

void loadRSAPubKey(RSA::PublicKey& key, const char* filename){
  ByteQueue byte;
  FileSource file(filename, true, new Base64Decoder);
  file.TransferTo(byte);
  byte.MessageEnd();
  key.Load(byte);
}
开发者ID:ssr341,项目名称:Cryptography-Cloud-Storage,代码行数:7,代码来源:utility.cpp

示例5: 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

示例6: LoadKey

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

示例7: CheckSignature

bool CheckSignature(const std::string& pubKey,
                    const std::string& message,
                    const std::string& signature)
{
    RSA::PublicKey publicKey;
    publicKey.Load(StringSource(pubKey, true).Ref());

    RSASSA_PKCS1v15_SHA_Verifier verifier(publicKey);
    try {
        StringSource(message+signature, true,
                     new SignatureVerificationFilter(
                     verifier, NULL,
                     SignatureVerificationFilter::THROW_EXCEPTION));
        return true;
    } catch (const std::exception&) {
        return false;
    }
}
开发者ID:GoBudokai,项目名称:ozifi,代码行数:18,代码来源:crypto.cpp

示例8: fileName

CryptoPP::RSA::PublicKey cKeysStorage::loadPubFile(std::string pPubKey)
{
	std::string fileName(pPubKey);
	//fileName += ".pub";
	std::cout << "Public key file: " << fileName << std::endl;
	/*std::string line;
	std::ifstream input(fileName);
	for (int i = 0; i < 3; i++)
	{
		input >> line;
		//std::cout << line << " ";
		input >> line;
		//std::cout << line << std::endl;
	}
	std::cout << "Load rsa data" << std::endl;
	input >> line; // END
	*/
	// load rsa data
	//char byte;
	
	//from .pub to tmp
	/*std::ofstream tmpFile("tmp", std::ios::trunc);
	
	while (!input.eof())
	{
		input >> std::noskipws >> byte;
		std::cout << byte;
		tmpFile << byte;
	}
	
	tmpFile.close();*/
	
	//Read public key
	CryptoPP::ByteQueue bytes;
	FileSource file(fileName.c_str(), true, new Base64Decoder);
	file.TransferTo(bytes);
	bytes.MessageEnd();
	RSA::PublicKey pubKey;
	pubKey.Load(bytes);
	
	std::cout << "end of loadPubFile" << std::endl;
	
	return pubKey;
}
开发者ID:Happuri,项目名称:chainsign,代码行数:44,代码来源:ckeysstorage.cpp

示例9: verify_signature

void BCipher::verify_signature(std::string content,std::string signature){
        std::cout<<"Receiver verifies signature using sender's publickey"<<std::endl;
        RSA::PublicKey rsaPublickey;
        {
         FileSource input("sender_public.dat", true);
         rsaPublickey.BERDecode(input);
        }
 
	RSASSA_PKCS1v15_SHA_Verifier verifier(rsaPublickey);
        StringSource ss4(content + signature, true,
           new SignatureVerificationFilter(
               verifier, NULL,
               SignatureVerificationFilter::THROW_EXCEPTION
          ) // SignatureVerificationFilter
        ); // StringSource

        std::cout << "Verified signature on message" << std::endl;

}
开发者ID:XuefengHuang,项目名称:Cloud_Encrypted,代码行数:19,代码来源:bcipher.cpp

示例10: GenerateRSAKey

/*
 * generate the RSA public key and private key in separate file
 */
void MyRSA::GenerateRSAKey(unsigned int keyLength, const char *privFilename,
                           const char *pubFilename)
{   AutoSeededRandomPool rng;
    RSA::PrivateKey priv;
    priv.GenerateRandomWithKeySize(rng, 1024);
    if (!priv.Validate(rng, 3))
    {
        throw("RSA key generation failed");
    }
	HexEncoder privFile(new FileSink(privFilename));
	priv.DEREncode(privFile);
	privFile.MessageEnd();
    
    
    RSA::PublicKey pub;
    pub.AssignFrom(priv);
	HexEncoder pubFile(new FileSink(pubFilename));
	pub.DEREncode(pubFile);
	pubFile.MessageEnd();
}
开发者ID:veteran12,项目名称:CryptographyProj,代码行数:23,代码来源:signaturekeygen.cpp

示例11: pubkey

int
main(int argc, char ** argv)
{
	if (argc != 2) {
		cout << "Usage: keygen <outputname>" << endl;
		return -1;
	}
	AutoSeededRandomPool rng;
	InvertibleRSAFunction params;
	params.GenerateRandomWithKeySize(rng, 3072);
	RSA::PublicKey pubkey(params);
	RSA::PrivateKey privkey(params);

	Integer m = params.GetModulus();
	Integer p = params.GetModulus();
	Integer q = params.GetModulus();
	Integer priv = params.GetPrivateExponent();
	Integer pub = params.GetPublicExponent();

	string privname = string(argv[1]).append(".priv");
	string pubname = string(argv[1]).append(".pub");

	CryptoEngine::pubkeyToFile(pubkey, pubname);
	CryptoEngine::privkeyToFile(privkey, privname);

	cout << "Loading and verifying..." << endl;

	RSA::PrivateKey newpriv = CryptoEngine::privkeyFromFile(privname);
	RSA::PublicKey newpub = CryptoEngine::pubkeyFromFile(pubname);

	cout << (m == newpriv.GetModulus() ? "TRUE" : "FALSE") << endl;
	cout << (priv == newpriv.GetPrivateExponent() ? "TRUE" : "FALSE") << endl;
	cout << (pub == newpriv.GetPublicExponent() ? "TRUE" : "FALSE") << endl;

	cout << (m == newpub.GetModulus() ? "TRUE" : "FALSE") << endl;
	cout << (pub == newpub.GetPublicExponent() ? "TRUE" : "FALSE") << endl;

	return 0;
}
开发者ID:keaneokelley,项目名称:InshtantMeshenger,代码行数:39,代码来源:keygen.cpp

示例12: VerifyLicense

int VerifyLicense(string signedTxt, string sigIn, string pubKeyEnc)
{
    //Read public key
    CryptoPP::ByteQueue bytes;
    StringSource file(pubKeyEnc, true, new Base64Decoder);
    file.TransferTo(bytes);
    bytes.MessageEnd();
    RSA::PublicKey pubKey;
    pubKey.Load(bytes);

    RSASSA_PKCS1v15_SHA_Verifier verifier(pubKey);

    //Read signed message
    CryptoPP::ByteQueue sig;
    StringSource sigFile(sigIn, true, new Base64Decoder);
    string sigStr;
    StringSink sigStrSink(sigStr);
    sigFile.TransferTo(sigStrSink);

    string combined(signedTxt);
    combined.append(sigStr);

    //Verify signature
    try
    {
        StringSource(combined, true,
                     new SignatureVerificationFilter(
                         verifier, NULL,
                         SignatureVerificationFilter::THROW_EXCEPTION
                     )
                    );
    }
    catch(SignatureVerificationFilter::SignatureVerificationFailed &err)
    {
        cout << err.what() << endl;
        return 0;
    }
    return 1;
}
开发者ID:hmkwizu,项目名称:rsa-license-key,代码行数:39,代码来源:verifyxmllicense.cpp

示例13: Verify

void Verify(){
	//Read public key
	CryptoPP::ByteQueue bytes;
	FileSource file("pubkey.txt", true, new Base64Decoder);
	file.TransferTo(bytes);
	bytes.MessageEnd();
	RSA::PublicKey pubKey;
	pubKey.Load(bytes);

	RSASSA_PKCS1v15_SHA_Verifier verifier(pubKey);

	//Read signed message
	string signedTxt;
	FileSource("message.dat", true, new StringSink(signedTxt)); //c
	string sig;
	FileSource("cipher.dat", true, new StringSink(sig)); //m

	string combined(signedTxt);
	combined.append(sig);

	//Verify signature
	try
	{
		StringSource(combined, true,
			new SignatureVerificationFilter(
				verifier, NULL,
				SignatureVerificationFilter::THROW_EXCEPTION
		   )
		);
		// cout << "Signature OK" << endl;
	}
	catch(SignatureVerificationFilter::SignatureVerificationFailed &err)
	{
		cout << err.what() << endl;
	}

}
开发者ID:gr347wh173n0r7h,项目名称:ParallelRSA,代码行数:37,代码来源:SingleRSA.cpp

示例14: EncryptAsymmetrical

std::string EncryptAsymmetrical(const std::string& pubKey, const std::string& data) {
    assert(!data.empty());
    string result;

    AutoSeededRandomPool rng;
    RSA::PublicKey publicKey;
    publicKey.Load(StringSource(pubKey, true).Ref());
    RSAES_OAEP_SHA_Encryptor e(publicKey);
    result.resize(2);
    *(ui16*)result.data() = 0;
    for (size_t i = 0; i <= (data.size() - 1) / MAX_DATA_SIZE; ++i) {
        string currData = data.substr(i * MAX_DATA_SIZE, MAX_DATA_SIZE);
        string currResult;
        StringSource ss(currData, true,
                        new PK_EncryptorFilter(rng, e,
                        new StringSink(currResult)));
        result.resize(result.size() + 2);
        (*(ui16*)(result.data() + result.size() - 2)) = currResult.size();
        (*(ui16*)(result.data()))++;
        result += currResult;
    }
    assert(!result.empty());
    return result;
}
开发者ID:GoBudokai,项目名称:ozifi,代码行数:24,代码来源:crypto.cpp

示例15: PrintPublicKey

void PrintPublicKey(const RSA::PublicKey& key)
{
  cout << "n: " << key.GetModulus() << endl;
  cout << "e: " << key.GetPublicExponent() << endl;
}
开发者ID:JetpackUnicorn,项目名称:ElephantParty,代码行数:5,代码来源:crypto++_authentication_TXT.cpp


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