Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException #3

Open
EdmondChuiHW opened this issue Jan 30, 2013 · 2 comments
Open

IllegalArgumentException #3

EdmondChuiHW opened this issue Jan 30, 2013 · 2 comments

Comments

@EdmondChuiHW
Copy link

Not sure if it is Android specific, but testing on both 2.3.6 and 4.1.1 devices causes this Exception.

E/AndroidRuntime(10087): java.lang.IllegalArgumentException: Bad limit (capacity 57): 73
E/AndroidRuntime(10087): at java.nio.Buffer.limitImpl(Buffer.java:312)
E/AndroidRuntime(10087): at java.nio.Buffer.limit(Buffer.java:303)
E/AndroidRuntime(10087): at org.keyczar.Encrypter.encrypt(Encrypter.java:166)
E/AndroidRuntime(10087): at org.keyczar.Encrypter.encrypt(Encrypter.java:114)
E/AndroidRuntime(10087): at org.keyczar.Encrypter.encrypt(Encrypter.java:186)

@kruton
Copy link
Owner

kruton commented Jan 31, 2013

Do you have a test case?

@EdmondChuiHW
Copy link
Author

I found out the reason while I'm testing. When the input is an empty String, the second entry after it will cause this error.

Here is a test case, after encrypting the first empty String, encrypting "Jacob" does not have any problem, however encrypting "Sophia" will cause such Exception to be thrown. And the solution is to do an empty String test.

I believe an empty String is not a valid input for the Crypter then.

Thanks!

package com.example.keyczartest;

import org.keyczar.Crypter;
import org.keyczar.exceptions.KeyczarException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.example.android.keyczardemo.AndroidKeyczarReader;
import com.example.android.keyczardemo.FixBrokenCipherSpiProvider;

public class MainActivity extends Activity {
    public static final String TAG = "MainActivity";
    public static String[] TEXT = {"ABCD1234", "UNKNOWN", "", "Jacob", "Sophia",
            "Mason", "Isabella", "William", "Emma", "Jayden", "Olivia", "Noah",
            "Ava", "Michael", "Emily", "Ethan", "Abigail", "", "Alexander", "",
            "Madison", "Aiden", "Mia", "Daniel", "Chloe"};

    static {
        FixBrokenCipherSpiProvider.insertIfNeeded();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView = (TextView)findViewById(android.R.id.text1);

        try {
            Crypter crypter = new Crypter(new AndroidKeyczarReader(getResources(), "test_keys_public_dont_not_use"));

            for (String string : TEXT) {
                // Solution
                // if (TextUtils.isEmpty(string)) {
                // continue;
                // }
                Log.d(TAG, "trying to encrypt: " + string);
                textView.append(crypter.encrypt(string));
                textView.append("\n");
            }
        } catch (KeyczarException e) {
            Log.e(TAG, "WHYYYYYYYYYYYYYYY D:", e);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants