krzyzanowskim / OpenSSL

OpenSSL package for SwiftPM, CocoaPod, and Carthage, multiplatform
https://swift.best
Other
910 stars 336 forks source link

RSA_size(rsa_key) Getting nill in iOS 13 + #76

Closed gaminilesh closed 4 years ago

gaminilesh commented 4 years ago

Hello, i develop RSA encryption with publicKey or decryption with privateKey using pod Universal-openssl. The problem is when i call RSA_public_encrypt method the result of " (unsigned char *) to " length is nill. iOS 13 or later RSA_size getting nill and Same Code working with iOS 12.3 earlier.

        encryptMessage = (char*)malloc(RSA_size(rsa_key));
        err1 = (char*)malloc(130);

        if((crypto_len = RSA_public_encrypt((int)strlen(msg), (unsigned char*)msg, (unsigned char*)encryptMessage, rsa_key, RSA_PKCS1_PADDING)) == -1) {

            ERR_load_crypto_strings();
            ERR_error_string(ERR_get_error(), err1);
            fprintf(stderr, "Error encrypting message: %s\n", err1);
//            goto free_stuff;

        }
krzyzanowskim commented 4 years ago

RSA_size(rsa_key) is a size value, it can't return NULL. malloc allocates memory and return a pointer to allocated memory. That said, depends what's in rsa_key, RSA_size() may return different value, see https://www.openssl.org/docs/man1.0.2/man3/RSA_size.html

I'm affraid that's all I can say here.