Ejemplo n.º 1
0
void OutputPair(const NameValuePairs &v, const char *name)
{
	Integer x;
	bool b = v.GetValue(name, x);
	assert(b);
	cout << name << ": \\\n    ";
	x.Encode(HexEncoder(new FileSink(cout), false, 64, "\\\n    ").Ref(), x.MinEncodedSize());
	cout << endl;
}
std::string Node::RSAdecrypt(Integer raw){
	AutoSeededRandomPool prng;
	raw = privKey.CalculateInverse(prng, raw);

	std::string recovered;
	recovered.resize(raw.MinEncodedSize());
	raw.Encode((byte *)recovered.data(), recovered.size());	
	return recovered;
}
//***************************************************************
Integer HashClass::getSHA1Integer(string m, Integer r)
{
    byte *encodedMessage = (byte *)m.c_str();
    int messageSize = m.length();
    int rSize = r.MinEncodedSize();
    byte * encodedR = new byte[rSize];
    r.Encode(encodedR, rSize);
    
    byte * hashInput = new byte[rSize + messageSize];
    copy(encodedMessage, encodedMessage + messageSize, hashInput);
    copy(encodedR, encodedR + rSize, hashInput + messageSize);
    byte *hashOutput = getSHA1(hashInput, rSize+messageSize);
    Integer result;
    r.Decode(hashOutput, HashClass::size);
    return r;
}
Ejemplo n.º 4
0
//********************************************************************************************************
SecByteBlock Converter::encodeSecByteBlock(Integer key)
{
    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;
}