I get an error trying to generate a key for certain devices. I\'m able to reproduce the error on a Samsung Galaxy Note running 4.4.2.
java.lang.IllegalStateExcep
If your code is OK then remember that you need to set up a PIN/PW/Fingerprint (Secure unlock) for your device so that the keystore starts functioning. A simple swipe will give such error if you try to generate keypairs.