Archived Forum Post

Index of archived forum posts

Question:

How to catch chilkat exception on Android NDK

Apr 07 '16 at 22:29

Hi,

I'am using Android NDK on Android Studio with Experimental Plugin(gradle). I built my library successfully with chilkat but I meeting some issue. When I send a invalid input string to chilkat decrypt method (decryptStringENC), my C++ code throw a exception that have this signal: SIGSEGV and I can't use try/catch to catch it (I included cppFlags.add("-fexceptions") in gradle). I try to use a thirdparty library: https://github.com/xroche/coffeecatch but after run code block in COFFEE_CATCH, the app was still crash with exception SIGSEGV. So do you have any solution for this? Thank you.


Accepted Answer

I suspect the crash is in your code:

    rsa.put_EncodingMode("hex");
    rsa.ImportPrivateKey("hello");
    string decryptedStr = rsa.decryptStringENC(
            "hello",
            true);
    return env->NewStringUTF(decryptedStr.c_str());
The call to rsa.decryptStringENC will return 0 if it failed. You're probably trying to dereference a null pointer in your C++ code..


Answer

Yes! My issue was solved! Thank you very much.


Answer

I don't know of how to catch the SIGSEGV, but the real solution is to fix the crash. Did this happen with the latest version of Chilkat? If not, then update to the latest version and test again.

If the crash was in the latest version, please post the string passed to decryptStringENC, along with the settings for EncodingMode, and other encryption property settings (CryptAlgorithm, CipherMode, KeyLength, etc.) If I can reproduce the problem, it is easily fixable.


Answer

I have downloaded lastest version. THis is my code:

string RSA::rsaDecrypt(string inputString, string privateKey) {
    string decryptedStr;
    CkRsa *rsa = Utils::getCkRsa();
    rsa->put_EncodingMode("hex");
    rsa->ImportPrivateKey(privateKey.c_str());
    decryptedStr = rsa->decryptStringENC(
            inputString.c_str(),
            true);
    return decryptedStr;

}

Anytime, if I give a invalid string to inputString (ex: "E00D"), decryptStringENC throw a error signal (SIGSEGV), then application crash. I tried to put call native method in a AsyncTask, sometime it doesn't crash but still happen many time.

For example, with these code, app will be crashed:

CkRsa rsa;
    bool success = rsa.UnlockComponent("UNLOCK KEY");
    if (success != true) {
        std::cout << rsa.lastErrorText() << "\r\n";
        return "";
    }
    rsa.put_EncodingMode("hex");
    rsa.ImportPrivateKey("hello");
    decryptedStr = rsa.decryptStringENC(
            "hello",
            true);

Answer

Thanks! I'll give it a try an will report back..


Answer

I'm not able to reproduce a crash...


Answer

Thanks, I downloaded it and deleted your link. :-)