MS CAPI PRIVATEKEYBLOB到RSA *

时间:2011-07-13 19:21:55

标签: windows openssl

我实现了这个并且收到错误:0407B07B:rsa例程:RSA_check_key:与1不一致

BitLen 1024,ModLen 128,Prime1,Prime2,Exponent1,Exponent2,系数长度= 64 PrivateExponent Len = 128

RSA* blobtorsa()
{
    BN_set_word(rsa->e, prsahdr->pubexp);
    lend_tobn(rsa->n, pbmod, cbmod);
    lend_tobn(rsa->p, pbprime1, cbprimes);
    lend_tobn(rsa->q, pbprime2, cbprimes);
    lend_tobn(rsa->d, pbprivexp, cbprivexp);
    // d mod ( p - 1 )
    BN_mod_sub(rsa->dmp1, rsa->d, BN_value_one(), rsa->p, ctx);
    // d mod (q-1)
    BN_mod_sub(rsa->dmq1, rsa->d, BN_value_one(), rsa->q, ctx);
    BIGNUM* negone = BN_new();
    BN_set_word(negone, -1);
    // q^-1 mod p
    BN_mod_exp(rsa->iqmp, rsa->q, negone, rsa->p, ctx);
    if ( RSA_check_key(rsa) == 0 )
    {
      print error
      error:0407B07B:rsa routines:RSA_check_key:d e not congruent to 1
    }
}

1 个答案:

答案 0 :(得分:0)

对于其他任何想知道的人 - 一旦你得到指针和大小分开 结构中的项目:

{
    BIGNUM* temp = BN_new();

    rsa->e = BN_new();
    BN_set_word(rsa->e, prsapk->pubexp);

    // set n, p, q and d from structures
    rsa->n = BN_new();
    lend_tobn(rsa->n, pbMod, cbMod);
    rsa->p = BN_new();
    lend_tobn(rsa->p, pbPrime1, cbPrime1);
    rsa->q = BN_new();
    lend_tobn(rsa->q, pbPrime2, cbPrime2);
    rsa->d = BN_new();
    lend_tobn(rsa->d, pbPrivateExponent, cbPrivateExponent);

    // calculate the remainder of properties

    // d mod (p-1)
    rsa->dmp1 = BN_new();
    BN_copy(temp, rsa->p);
    BN_sub_word(temp, 1);
    BN_mod(rsa->dmp1, rsa->d, temp, ctx);

    // d mod (q-1)
    rsa->dmq1 = BN_new();
    BN_copy(temp, rsa->q);
    BN_sub_word(temp, 1);
    BN_mod(rsa->dmq1, rsa->d, temp, ctx);

    // q^-1 mod p
    rsa->iqmp = BN_new();
    BN_mod_inverse(rsa->iqmp, rsa->q, rsa->p, ctx);

    BN_free(temp);

    BN_CTX_end(ctx);
    BN_CTX_free(ctx);

    ERR_clear_error();
    if ( RSA_check_key(rsa) == 1 )
            {
            }

}