creating public RSA key and verifying signature - Openssl

This is a discussion on creating public RSA key and verifying signature - Openssl ; hi, i tried to verify a signature but it fails giving an error code of -1. can anyone tell me where i might had gone wrong? i used the RSA_public_decrypt which i think should be the correct function to use. ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: creating public RSA key and verifying signature

  1. creating public RSA key and verifying signature

    hi, i tried to verify a signature but it fails giving an error code of -1.
    can anyone tell me where i might had gone wrong?
    i used the RSA_public_decrypt which i think should be the correct function
    to use.
    pValidationData.rgbValidationData has been signed previously using the
    private key.
    i'm suspecting it could be some problem with lengths of the variables.

    publicKey = RSA_new();

    RSAModulus = BN_new();
    BN_bin2bn(prgbAttribData, pulAttribDataSize, RSAModulus);
    publicKey->n = RSAModulus;

    RSAExponent = BN_new();
    BN_hex2bn(&RSAExponent, "010001");
    publicKey->e = RSAExponent;

    outputPlaintext = (unsigned char *)OPENSSL_malloc((unsigned
    int)pValidationData.ulValidationDataLength);

    // RSA_size(publicKey) returns 256
    // pValidationData.ulValidationDataLength is 256 too

    result = RSA_public_decrypt(pValidationData.ulValidationDat aLength,
    pValidationData.rgbValidationData, outputPlaintext, publicKey,
    RSA_PKCS1_PADDING);

    if (result == -1) {
    printf("RSA public dncrypt error!\n");
    ERR_get_error();
    }

    I know this isn't a lot of information why it failed, how do i find out more
    about what went wrong?

    thanks - adrian


  2. Re: creating public RSA key and verifying signature

    btw, when i try to get the error code by
    printf("Error code: %d", ERR_get_error());

    i get Error code: 67567722

    thanks- adrian

    On Mon, Oct 13, 2008 at 11:21 AM, adrian golding wrote:

    > hi, i tried to verify a signature but it fails giving an error code of -1.
    > can anyone tell me where i might had gone wrong?
    > i used the RSA_public_decrypt which i think should be the correct function
    > to use.
    > pValidationData.rgbValidationData has been signed previously using the
    > private key.
    > i'm suspecting it could be some problem with lengths of the variables.
    >
    > publicKey = RSA_new();
    >
    > RSAModulus = BN_new();
    > BN_bin2bn(prgbAttribData, pulAttribDataSize, RSAModulus);
    > publicKey->n = RSAModulus;
    >
    > RSAExponent = BN_new();
    > BN_hex2bn(&RSAExponent, "010001");
    > publicKey->e = RSAExponent;
    >
    > outputPlaintext = (unsigned char *)OPENSSL_malloc((unsigned
    > int)pValidationData.ulValidationDataLength);
    >
    > // RSA_size(publicKey) returns 256
    > // pValidationData.ulValidationDataLength is 256 too
    >
    > result = RSA_public_decrypt(pValidationData.ulValidationDat aLength,
    > pValidationData.rgbValidationData, outputPlaintext, publicKey,
    > RSA_PKCS1_PADDING);
    >
    > if (result == -1) {
    > printf("RSA public dncrypt error!\n");
    > ERR_get_error();
    > }
    >
    > I know this isn't a lot of information why it failed, how do i find out
    > more about what went wrong?
    >
    > thanks - adrian
    >



  3. RE: creating public RSA key and verifying signature



    > btw, when i try to get the error code by
    > printf("Error code: %d", ERR_get_error());


    > i get Error code: 67567722


    Your code says:

    result = RSA_public_decrypt(pValidationData.ulValidationDat aLength,
    pValidationData.rgbValidationData, outputPlaintext, publicKey,
    RSA_PKCS1_PADDING);

    Are you 100% sure the data had PKCS#1 v1.5 padding?

    error:0407006A:rsa routines:RSA_padding_check_PKCS1_type_1:block type is not
    01

    DS


    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


+ Reply to Thread