Hi,
I am new to Cryptopp library. In my application I have to verify
signature using RSA SSA PKCS1 v 1.5 signature scheme. I have the
public key(modulus-3072bits and exponent-8bits ), message(1104 bits)
and signature(3072 bits) all in raw hexadecimal representation.
I am trying to use Cryptopp library to verify the above given
signature, but I get the following error..
Error: CryptoMaterial: this object contains invalid values
can I load the hexadecimal value directly into the message, signature
and public key (modulus and exponent) variables?
I used pubkey.Initialize(modulus, exp) function to load modulus and
exponent into RSA::PublicKey pubkey;
could anyone please help me where I went wrong.
Thanks in advance.
Shiva
my code:
#include "stdio.h"
#include "stdlib.h"
#include "StdAfx.h"
#include <cryptopp/rsa.h>
using CryptoPP::RSA;
using CryptoPP::InvertibleRSAFunction;
using CryptoPP::RSASSA_PKCS1v15_SHA_Signer;
using CryptoPP::RSASSA_PKCS1v15_SHA_Verifier;
#include <cryptopp/pssr.h>
using CryptoPP::PSS;
#include "cryptopp/sha.h"
using CryptoPP::SHA1;
#include "cryptopp/files.h"
using CryptoPP::FileSink;
using CryptoPP::FileSource;
#include "cryptopp/osrng.h"
using CryptoPP::AutoSeededRandomPool;
#include "cryptopp/secblock.h"
using CryptoPP::SecByteBlock;
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;
#include <cryptopp/integer.h>
int main(int argc, char* argv[])
{
try
{
////////////////////////////////////////////////
// Load keys
RSA::PublicKey pubkey;
const byte hex_modulus[384]= {0xA2,0xC7,0x55,0x57,0x54,0xCB,
0xAA,0xA7,0x7A,0x27,0x92,0xC3,0x1A,0x6D,0xC2,0x31,0xCF,
0x12,0xC2,0x24,0xBF,0x89,0x72,0x46,0xA4,0x8D,0x20,0x83,0xB2,0xDD,
0x04,0xDA,0x7E,0x01,0xA9,0x19,0xEF,0x7E,0x8C,
0x47,0x54,0xC8,0x59,0x72,0x5C,0x89,0x60,0x62,0x9F,
0x39,0xD0,0xE4,0x80,0xCA,0xA8,0xD4,0x1E,0x91,0xE3,0x0E,0x2C,
0x77,0x55,0x6D,0x58,0xA8,0x9E,0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,0x7A,0x24,0xDD,0xD1,0x3A,
0xB7,0x3A,0xB0,0xBB,0xE5,0xD1,0x28,0xAB,0xAD,0x24,0x54,0x72,0x0E,
0x76,0xD2,0x89,0x32,0xEA,0x46,0xD3,0x78,0xD0,0xA9,0x67,0x78,0xC1,0x2D,
0x18,0xB0,0x33,0xDE,0xDB,0x27,0xCC,0xB0,0x7C,0xC9,0xA4,0xBD,0xDF,0x2B,
0x64,0x10,0x32,0x44,0x06,0x81,0x21,0xB3,0xBA,0xCF,0x33,0x85,0x49,0x1E,
0x86,0x4C,0xBD,0xF2,0x3D,0x34,0xEF,0xD6,0x23,0x7A,0x9F,0x2C,0xDA,
0x84,0xF0,0x83,0x83,0x71,0x7D,0xDA,0x6E,0x44,0x96,0xCD,0x1D,0x05,0xDE,
0x30,0xF6,0x1E,0x2F,0x9C,0x99,0x9C,0x60,0x07};
const byte hex_exp = 0x03;
const CryptoPP::Integer modulus(&hex_modulus[0], 768,
CryptoPP::Integer::UNSIGNED);
const CryptoPP::Integer exp(&hex_exp, 1,
CryptoPP::Integer::UNSIGNED);
const byte message[138] = {0x74,0x5b,0xb8,0xbd,0x04,0xbc,
0x83,0xc7,0x95,0x78,0xf9,0x0c,0x91,0x4b,0x89,0x38,0x05,0x5a,0xa4,0xac,
0x1f,0xa8,0x03,0x93,0x82,0x79,0x75,0xaf,0x66,0x22,0xde,0x43,0x80,0x8d,
0xcd,0x5d,0x90,0xb8,0x3c,0xb3,0xd8,0x9e,0xb0,0x0d,0x09,0x44,0xf4,0x3f,
0x5f,0xab,0xb9,0xc4,0xc9,0x96,0xef,0x78,0xb5,0x8f,0x69,0x77,0xb4,0x7d,
0x08,0x14,0x9c,0x81,0xa0,0x8f,0x04,0x1f,
0xa0,0x88,0xe1,0x20,0xc7,0x34,0x4a,0x49,0x35,0x65,0x99,0xcf,
0x53,0x19,0xf0,0xc6,0x81,0x76,0x05,0x5c,0xb9,0xde,0xdd,0xab,0x3d,
0xb0,0x92,0xa1,0x23,0x4f,0x0c,0x71,0x30,0x42,0x78,0xf6,0x55,0xae,0xbd,
0x36,0x25,0x8e,0x25,0x0d,0x4e,0x5e,0x8e,0x77,0x6a,
0x60,0xe3,0xc1,0xe9,0xee,0xcd,0x2b,0x9e,
0x18,0x63,0x97,0xd4,0xe6,0x75,0x01,0x00,0x01,0x00,0x00};
pubkey.Initialize(modulus, exp);
const byte signature[384] = {0x1d,0x0a,0x61,0xea,0xab,
0xf8,0xa8,0x2b,0x02,0x69,0xa1,0x34,0xfd,0x91,0xac,0x2b,0xf2,0x8f,
0x34,0x8b,0xd4,0x84,0xfa,0x62,0xbc,0x01,0x4a,0x4a,0xa2,0xb2,0x14,0xbf,
0xb5,0xf4,0xdf,0xac,0x80,0x93,0x0d,0x13,0xec,0x9c,
0xe5,0xd8,0x34,0x70,0x51,0x9a,0x66,0x80,0xeb,0xbe,0xcc,0x7e,
0x45,0xf0,0xe6,0x39,0x63,0x84,0xc9,0xb9,0x8e,0x8c,0xaf,0x9c,
0xa9,0xd4,0x0e,0xeb,0x9a,0x57,0x2a,0x17,0x41,0xca,
0x97,0xf3,0x19,0x96,0xb5,0x5d,0x0f,0x30,0xa3,0x84,0xe5,0x73,0xa2,0xed,
0x05,0x69,0x7a,0x22,0xce,0x84,0x1f,0x3e,0x39,0x9e,0x28,0x76,0xc9,0xbc,
0x89,0x5b,0x70,0xb1,0x7b,0xf4,0xed,0xb6,0x74,0x12,0xab,
0x48,0x29,0x64,0xce,0x6c,0x60,0x04,0xeb,0xa9,0x7a,
0xa2,0x15,0xa6,0x58,0x9a,0xad,0x32,0xc7,0x53,0x39,0xe5,0xfe,
0xf0,0x37,0xa7,0xa0,0xc5,0xff,0xec,0xd9,0xb0,0x05,0xbb,
0x25,0x13,0xa0,0xa4,0xc7,0x0b,0x2a,0x5d,0xc6,0x8f,0x51,0x11,0xcb,
0x36,0xed,0x5c,0x17,0x7e,0x22,0x20,0xc3,0xeb,0x40,0x8c,0x67,0xbb,0x1c,
0xd2,0x47,0xb0,0xe0,0xbd,0xe7,0x4c,0xcd,0x5d,0xd5,0x23,0x12,0xf8,0x3b,
0x1d,0x91,0x3b,0xf3,0xc7,0x60,0xea,0x90,0x24,0x48,0xe5,0x92,0x21,0x6c,
0xf6,0xd9,0x5e,0x76,0x8d,0x2b,0x86,0xa6,0x7c,0x16,0xae,
0xa8,0x36,0x08,0xa0,0x37,0x14,0x1a,0xd7,0x03,0xe1,0x40,0x31,0xca,0x6c,
0x95,0xe0,0x10,0xb0,0x43,0xcf,0xb7,0xe0,0x30,0x05,0xb9,0xac,
0xb7,0x08,0x68,0xcd,0x7e,0x11,0x47,0x2a,0x03,0x3b,0xeb,
0x74,0xc8,0x19,0x62,0x8b,0x2f,0x11,0x91,0xb6,0x06,0x4f,0xe0,0x2a,
0x44,0x20,0x43,0x29,0x13,0x1f,0xdd,0xd0,0x4a,0x11,0x6c,0x0e,0x83,0xbf,
0x22,0x62,0x3b,0xeb,0xec,0xd7,0x76,0x28,0xba,
0x64,0x88,0x42,0xc8,0x73,0xa7,0x9e,0x4a,0x69,0x3a,0xb2,0x0c,0x4b,0x3a,
0xd9,0x50,0xdb,0x7c,0x51,0xee,0x15,0xe0,0x6b,0x2c,
0x63,0xa6,0x91,0x57,0xdd,0xbf,0x17,0x47,0x23,0xad,0x15,0xcb,
0xb9,0x91,0x18,0x0b,0x51,0x8f,0xf9,0x1c,0x51,0x67,0xc1,0x0b,
0x78,0xf5,0xd9,0x55,0xdc,0x48,0xe4,0xc0,0x83,0xa5,0xdf,0x75,0xe2,0xdc,
0x88,0xd2,0xc6,0xdd,0xdf,0x1f,0x37,0x90,0x35,0xf6,0xfd,0xda,
0xe0,0x04,0x32,0x69,0xc1,0xaf,0xd9,0xf9,0x11,0xc5,0xaa,
0x74,0x58,0x32,0x1c,0x71,0xaa,0xa7,0x14,0xfb,0x23,0x17,0x22};
SecByteBlock sign((unsigned char *)&signature, 384);
RSASSA_PKCS1v15_SHA_Verifier verifier( pubkey );
// Verify
bool result = verifier.VerifyMessage( (const byte *)&message,
138, sign, 384 );
// Result
if( true == result ) {
cout << "Signature on message verified" << endl;
} else {
cout << "Message verification failed" << endl;
}
} // try
catch( CryptoPP::Exception& e ) {
std::cerr << "Error: " << e.what() << std::endl;
}
return 0;
}
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
To unsubscribe from this group, send email to
cryptopp-users+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.