src/utils/crypto_utils/src/crypto_lib.c
CryptoKeyHandle RSAKey_ObjFromStrings(const char* N, const char* e)
{
    EVP_PKEY* result = NULL;
    EVP_PKEY* pkey = NULL;
    BIGNUM* M = NULL;
    BIGNUM* E = NULL;

    RSA* rsa = RSA_new();
    if (rsa == NULL)
    {
        goto done;
    }

    M = BN_new();
    if (M == NULL)
    {
        goto done;
    }

    E = BN_new();
    if (E == NULL)
    {
        goto done;
    }

    if (BN_hex2bn(&M, N) == 0)
    {
        goto done;
    }

    if (BN_hex2bn(&E, e) == 0)
    {
        goto done;
    }

    if (RSA_set0_key(rsa, M, E, NULL) == 0)
    {
        goto done;
    }

    pkey = EVP_PKEY_new();
    if (EVP_PKEY_assign_RSA(pkey, rsa) == 0)
    {
        goto done;
    }

    result = pkey;

done:
    if (result == NULL)
    {
        BN_free(M);
        BN_free(E);
        EVP_PKEY_free(pkey);
    }

    return CryptoKeyHandleToEVP_PKEY(result);
}
/**
 *@brief Makes an RSA Key from the base64 encoded strings of the modulus and exponent
 *@param encodedN a string of the modulus encoded in base64
 *@param encodede a string of the exponent encoded in base64
 *@return NULL on failure and a pointer to a key on success
 */
@brief Makes an RSA Key from the base64 encoded strings of the modulus and exponent
@param encodedN a string of the modulus encoded in base64
@param encodede a string of the exponent encoded in base64
@return NULL on failure and a pointer to a key on success
@brief Makes an RSA Key from the base64 encoded strings of the modulus and exponent @param encodedN a string of the modulus encoded in base64 @param encodede a string of the exponent encoded in base64 @return NULL on failure and a pointer to a key on success
CryptoKeyHandle RSAKey_ObjFromStrings(const char* N, const char* e)
{
    EVP_PKEY* result = NULL;
    EVP_PKEY* pkey = NULL;
    BIGNUM* M = NULL;
    BIGNUM* E = NULL;
    RSA* rsa = RSA_new();
    if (rsa == NULL)
    {
        goto done;
    }
    M = BN_new();
    if (M == NULL)
    {
        goto done;
    }
    E = BN_new();
    if (E == NULL)
    {
        goto done;
    }
    if (BN_hex2bn(&M, N) == 0)
    {
        goto done;
    }
    if (BN_hex2bn(&E, e) == 0)
    {
        goto done;
    }
    if (RSA_set0_key(rsa, M, E, NULL) == 0)
    {
        goto done;
    }
    pkey = EVP_PKEY_new();
    if (EVP_PKEY_assign_RSA(pkey, rsa) == 0)
    {
        goto done;
    }
    result = pkey;
done:
    if (result == NULL)
    {
        BN_free(M);
        BN_free(E);
        EVP_PKEY_free(pkey);
    }
    return CryptoKeyHandleToEVP_PKEY(result);
}
CryptoKeyHandle RSAKey_ObjFromStrings ( const char * N , const char * e ) { EVP_PKEY * result = NULL ; EVP_PKEY * pkey = NULL ; BIGNUM * M = NULL ; BIGNUM * E = NULL ; RSA * rsa = RSA_new ( ) ; if ( rsa == NULL ) { goto done ; } M = BN_new ( ) ; if ( M == NULL ) { goto done ; } E = BN_new ( ) ; if ( E == NULL ) { goto done ; } if ( BN_hex2bn ( & M , N ) == 0 ) { goto done ; } if ( BN_hex2bn ( & E , e ) == 0 ) { goto done ; } if ( RSA_set0_key ( rsa , M , E , NULL ) == 0 ) { goto done ; } pkey = EVP_PKEY_new ( ) ; if ( EVP_PKEY_assign_RSA ( pkey , rsa ) == 0 ) { goto done ; } result = pkey ; done : if ( result == NULL ) { BN_free ( M ) ; BN_free ( E ) ; EVP_PKEY_free ( pkey ) ; } return CryptoKeyHandleToEVP_PKEY ( result ) ; }
@brief Makes an RSA Key from the base64 encoded strings of the modulus and exponent
@param encodedN a string of the modulus encoded in base64
@param encodede a string of the exponent encoded in base64
@return NULL on failure and a pointer to a key on success
@brief Makes an RSA Key from the base64 encoded strings of the modulus and exponent @param encodedN a string of the modulus encoded in base64 @param encodede a string of the exponent encoded in base64 @return NULL on failure and a pointer to a key on success