Archived Forum Post

Index of archived forum posts

Question:

CkEncryptFile failed on Android

Dec 19 '14 at 08:54

Hi,

I am trying to integrate Chilkat into my Android app, I tried to encrypt a file from gallery into local app folder. I checked the result is always successful, but no data is written to the encrypted file. Can you help me if I did anything wrong? I have below permission in AndroidManifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Below is my code:

public static CkByteData createByteData(byte[] bytes) {
    CkByteData data = new CkByteData();
    data.appendByteArray(bytes);
    return data;
}
public static CkCrypt2 createCrypt(byte[] aesKey, byte[] iv) {
    CkCrypt2 crypt = new CkCrypt2();

    boolean success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        System.out.println(crypt.lastErrorText());
        return null;
    }

    crypt.put_CryptAlgorithm("AES");
    crypt.put_CipherMode("CTR");
    crypt.put_KeyLength(256);
    crypt.put_PaddingScheme(0);

    CkByteData keyData = createByteData(aesKey);
    crypt.put_SecretKey(keyData);

    CkByteData ivData = createByteData(iv);
    crypt.put_IV(ivData);

    return crypt;
}

public static void encrypt(File in, File out, byte[] aesKey, byte[] iv) throws IOException {
    CkCrypt2 ckCrypt2 = createCrypt(aesKey, iv);
    boolean res = ckCrypt2.CkEncryptFile(in.getAbsolutePath(), out.getAbsolutePath());
    LogHelper.log("Res " + res + ckCrypt2.lastErrorText() + " encrypted size " + out.length());
}

The log file is as below

Res trueChilkatLog:
CkEncryptFile:
DllDate: Dec  5 2014
ChilkatVersion: 9.5.0.46
UnlockPrefix: Anything for 30-day trial
Architecture: Little Endian; 32-bit
Language: Android Java
VerboseLogging: 0
inputFile: [/storage/sdcard0/DCIM/100MEDIA/IMAG0041.jpg]
outputFile: [/data/data/com.myapp.privatebox/files/xclrLjKQ0b/FILES/xclrLjKQ0b@L3N0b3JhZ2Uvc2RjYXJkMC9EQ0lNLzEwME1FRElBL0lNQUcwMDQxLmpwZw==@1413775350000@877222.jpg]
encryptionMethod: 2
inFileSize: 877222
Success.
--CkEncryptFile
--ChilkatLog
in /storage/sdcard0/DCIM/100MEDIA/IMAG0041.jpg encrypted size 0

Thank you, Thomas


Answer

Thomas,

Thanks. Turn on verbose logging by setting the CkCrypt's VerboseLogging property = true, and then post the verbose LastErrorText. Maybe we can get more information to help understand what's happening..

(I'll unsuspend your forum account. New accounts are automatically suspended because of SPAM attacks that are constant and ongoing..)