本文整理汇总了C++中SecByteBlock::Assign方法的典型用法代码示例。如果您正苦于以下问题:C++ SecByteBlock::Assign方法的具体用法?C++ SecByteBlock::Assign怎么用?C++ SecByteBlock::Assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecByteBlock
的用法示例。
在下文中一共展示了SecByteBlock::Assign方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encodeSecByteBlockWithLength
SecByteBlock Converter::encodeSecByteBlockWithLength(Integer key, int length)
{
//int length = key.MinEncodedSize();
byte * byteX;
key.Encode(byteX, length);
SecByteBlock pubKeyA;
pubKeyA.Assign(byteX, length);
std::cout<<"Key: " << key <<std::endl;
std::cout<<"Decoded: " << decodeSecByteBlock(pubKeyA) <<std::endl;
//check
if (key != decodeSecByteBlock(pubKeyA))
std::cout << "Error while encoding Integer to SecByteBlock" << std::endl;
return pubKeyA;
}
示例2: rng
void CryptoSession::parseAuthenticate2Reply(const string &bobPacket)
{
/* Alice verifies that the random string she sent bob is included in bobs msg */
AutoSeededRandomPool rng(false,128);
int len;
Storage::sectionType s;
StringSource pct(bobPacket,true,new Base64Decoder(new Gunzip));
len = pct.MaxRetrievable();
byte *tmp = new byte[len];
pct.Get(tmp,len);
Storage r;
r.setData(len,tmp);
s=r.readSection(0);
Storage::sectionType s2 = r.readSection(1);
/* verify signature */
StringSource pubFile(peer.getPubkey().c_str(),true,new HexDecoder);
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
if ((unsigned)s2.second.second!=pub.SignatureLength())
{
cout << "you puny earthling!\n";
debug() << "Bleh!!" << endl;
}
SecByteBlock signature(pub.SignatureLength());
signature.Assign(s2.second.first,s2.second.second);
VerifierFilter *verifierFilter = new VerifierFilter(pub);
verifierFilter->PutSignature(signature);
StringSource f(s.second.first,s.second.second, true, verifierFilter);
byte result = 0;
f.Get(result);
if (result != 1)
{
cout << "you deserve a horrible pimple on your nose\n";
debug() << "Bleh!!" << endl;
}
else
cout << "Signature verified\n";
/* Alice now decrypts the signed packet */
cout <<"Data : ";
StringSource(s.second.first,s.second.second,true,new HexEncoder(new FileSink(cout)));
cout << "\n";
StringSource privFile(privKey, true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor priv(privFile);
SecByteBlock buf;
buf.Assign(s.second.first,s.second.second);
byte *outstr = new byte[priv.MaxPlainTextLength()+1];
unsigned messageLength = priv.Decrypt(buf,outstr);
cout << messageLength << " " << s.second.second<< endl;
Storage msg;
msg.setData(messageLength,outstr);
s=msg.readSection(0);
cout << s.first << endl;
if (s.first != IDENTITY)
{
cout << "you suck way too much!\n";
debug() << "Bleh!!" << endl;
}
cout << s.second.first << endl;
// byte *sessionKey;
//int sessionKeyLen;
s=msg.readSection(1);
if (s.first != RANDOMDATA)
{
cout << "you suck too much ass!\n";
debug() << "Bleh!!" << endl;
}
int randomDataLen=s.second.second;
byte *randomData=new byte[randomDataLen];
memcpy(randomData,s.second.first,randomDataLen);
cout <<"\nRandom data we sent: ";
StringSource(randomData,randomDataLen,true,new HexEncoder(new FileSink(cout)));
cout << "\n";
// assert this str is equal to the random string we sent earlier.
s = msg.readSection(2);
if (s.first != SESSIONKEY2)
{
cout << "you suck way too much ass!\n";
debug() << "Bleh!!" << endl;
}
sessionKey2Len=s.second.second;
sessionKey2=new byte[sessionKey2Len];
memcpy(sessionKey2,s.second.first,sessionKey2Len);
cout <<"Sessionkey2: ";
StringSource(sessionKey2,sessionKey2Len,true,new HexEncoder(new FileSink(cout)));
cout << "\n";
//.........这里部分代码省略.........
示例3: parseAuthenticateReply
// Bob
void CryptoSession::parseAuthenticateReply(const string &alicePacket)
{
AutoSeededRandomPool rng(false,128);
int len;
Storage::sectionType s;
StringSource pct(alicePacket,true,new Base64Decoder(new Gunzip));
len = pct.MaxRetrievable();
byte *tmp = new byte[len];
pct.Get(tmp,len);
Storage r;
r.setData(len,tmp);
s=r.readSection(0);
if (s.first != CERTIFICATE)
{
cout << "Corrupt packet\n";
debug() << "Bleh!!" << endl;
}
/* Bob verifies the validity of the certificate */
Certificate c(s.second.first,s.second.second);
cout << "Version: "<< c.getVersion() << endl;
cout << "Serial: "<< c.getSerial() << endl;
cout << "Issuer: "<< c.getIssuer() << endl;
cout << "Subject: "<< c.getSubject() << endl;
cout << "Pubkey Algorithm: "<< c.getPubkeyAlgorithm() << endl;
cout << "Pubkey: "<< c.getPubkey() << endl;
if (c.verify(""))
cout << "Certificate verified!\n";
else
cout << "************ invalid certificate! **************\n";
peer = c;
/* Bob verifies her signature */
s=r.readSection(1);
Storage::sectionType s2 = r.readSection(2);
StringSource pubFile(c.getPubkey().c_str(),true,new HexDecoder);
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
if ((unsigned)s2.second.second!=pub.SignatureLength())
{
cout << "Alices signature is invalid\n";
debug() << "Bleh!!" << endl;
}
SecByteBlock signature(pub.SignatureLength());
signature.Assign(s2.second.first,s2.second.second);
VerifierFilter *verifierFilter = new VerifierFilter(pub);
verifierFilter->PutSignature(signature);
StringSource f(s.second.first,s.second.second, true, verifierFilter);
byte result = 0;
f.Get(result);
if (result != 1)
{
cout << "Alices signature is invalid\n";
debug() << "Bleh!!" << endl;
}
/* Bob now decrypts the signed packet */
cout <<"Data : ";
StringSource(s.second.first,s.second.second,true,new HexEncoder(new FileSink(cout)));
cout << "\n";
StringSource privFile(privKey, true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor priv(privFile);
SecByteBlock buf;
buf.Assign(s.second.first,s.second.second);
byte *outstr = new byte[priv.MaxPlainTextLength()+1];
unsigned messageLength = priv.Decrypt(buf,outstr);
cout << messageLength << " " << s.second.second<< endl;
Storage msg;
msg.setData(messageLength,outstr);
s=msg.readSection(0);
cout << s.first << endl;
if (s.first != IDENTITY)
{
cout << "you suck too much!\n";
debug() << "Bleh!!" << endl;
}
cout << s.second.first << endl;
s=msg.readSection(1);
if (s.first != SESSIONKEY)
{
cout << "you suck too much ass!\n";
debug() << "Bleh!!" << endl;
}
sessionKeyLen=s.second.second;
sessionKey=new byte[sessionKeyLen];
memcpy(sessionKey,s.second.first,sessionKeyLen);
//.........这里部分代码省略.........