signature=1b21bbbc45815e29993271276a4b5eff,c++ - RAW RSA signature verification with crypto++ librar...

How it is possible to verify a digital signature with the crypto++ library?

The input data is:

public_key BASE64 encoded hex string.

public exponent from the public key.

signature as hex string.

I don't know the private key part.

I have written this test function but it alway ends with "VerifierFilter: digital signature not valid" error.

The key here is exported from a valid KeyPair!

void rawRSAVerificationTest()

{

// RSA 2048 digital signature verification

try {

std::string pupKeyStr ("e0c3851114c758fb943a30ca8f9b4c7f506d52aa101c34ad5134f2cdbdddbef11ee6d1470d54caf3774d4d17d69488abf0b78beaebc046115cb29617610e98be3d5c303e19c14ae57ce0994701e3f24a628abf5c421777fb3c2b9b8b17f2a4cda4b9fd89e3c122085831c3e4502734bc3f3157d3ccd01198a8e3795f03661b55112acb69e8d5782bdf506bf5222777baf382d4d4bc2dd83e53af9236ed6e7a0fb8b5bb543ed4abbf478911bdc517e13e580b138f10f153eb2733ad60f3796e99b7d59f9abbd6666c69ba5ecc17a391424dc8ca3cf24a759c62d490056cda30265e11e316e7695028721c50eaf8e596161f0b59e4f598c85063bb3a847a5acb9d");

//sha256 hashed data signature

std::string signatureStr = "d8d1df600d6781a9c030d9c697ec928eac34bf0670cf469f7fffb9c046deaee359b4e1218b419ff2589434510db8470ccf7abd28876a04b8d5a27293723e897f97a9367d2fbb379f8c52ec2a04cb71a06891a3f44d00e8bb9622b2038dbe6f29d0118203c372853ae09fb820702f1c16ee772998bd8a3db9e5127992a18d999fc422822caf0a82d9c12d6231605457ce651b0350b1e98584f9d4e6b973d6668df863d4b73784bbc00d8449918a0f049ddbeffc0d79579ade13a2d9012906b7ded7aae934bc54c5b85c924aee6627d66b7b200a23cd9b6a9c14650f1f9384e9ef9b90ac217ece026a1802bc0623150057ecd2b31f5f758e4ff866bb2e81d28368";

//Chinese Remainder Theorem (CRT)

std::string pupExpStr ("0x10001");

CryptoPP::AutoSeededRandomPool rng;

CryptoPP::RSA::PublicKey pubKeyRaw;

CryptoPP::Integer pup_key_cast( static_cast<:integer> (pupKeyStr.c_str()));

CryptoPP::Integer pup_exp_cast( static_cast<:integer> (pupExpStr.c_str()));

pubKeyRaw.Initialize(pup_key_cast, pup_exp_cast);

if (!pubKeyRaw.Validate(rng, 3))

{

std::cout << "Error while public key validation" << std::endl;

}

CryptoPP::RSASS<:pss cryptopp::sha256>::Verifier verifier_sha256(pubKeyRaw);

CryptoPP::StringSource( signatureStr, true,

new CryptoPP::SignatureVerificationFilter(

verifier_sha256, NULL,

CryptoPP::SignatureVerificationFilter::THROW_EXCEPTION

) // SignatureVerificationFilter

); // StringSource

}

catch( CryptoPP::Exception& e )

{

std::cerr << "ERROR: " << e.what() << std::endl;

}

catch( ... )

{

std::cerr << "ERROR: Unknown verify signature error" << std::endl;

}

}

What i have missed?

I will be very grateful for any help!

Thanks in advance!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值