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

Exception casting to RSAPublicKey #4

Open
andy9775 opened this issue May 30, 2016 · 9 comments
Open

Exception casting to RSAPublicKey #4

andy9775 opened this issue May 30, 2016 · 9 comments

Comments

@andy9775
Copy link
Contributor

andy9775 commented May 30, 2016

When running on API 23 there seems to be an issue with RSAPublicKey. Possible cause: http://stackoverflow.com/questions/32400689/crash-casting-androidkeystorersaprivatekey-to-rsaprivatekey

More info:
the exception is,
java.lang.ClassCastException: android.security.keystore.AndroidKeyStoreECPublicKey cannot be cast to java.security.interfaces.RSAPublicKey
This happens inside this code block

 String alias = getUniqueDeviceId(this.context);
        try {
            final KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) keyStoreInstance.getEntry(alias, null);
            final RSAPublicKey publicKey = (RSAPublicKey) privateKeyEntry.getCertificate().getPublicKey();
            return crypto.encrypt(input, publicKey);
        } catch (NoSuchAlgorithmException |
                UnrecoverableEntryException |
                KeyStoreException e) {
            Log.e("QlassifiedKeyStore", String.format("Could not encrypt this string. Stacktrace: %s", e));
            return null;
        }

In the QlassifiedKeyStore.encrypt method.
I have the code running on both an emulator with 6.0 and a device with 6.0.1.

@nmalcolm
Copy link

I'm getting this error after generating a signed APK and trying to encrypt a string. However, it works fine while debugging with Android Studio.

QlassifiedCrypto: Could not encrypt this string. Stacktrace: java.security.NoSuchAlgorithmException: Provider SC does not provide RSA/NONE/PKCS1Padding

Unfortunately my crypto and Java knowledge is too weak to figure out the cause.

I'm using your fork along with the patch from #1.

@andy9775
Copy link
Contributor Author

andy9775 commented Jun 11, 2016

@nmalcolm are you getting that error with my pull request (my fork) and a signed apk? Try https://github.com/andy9775/Qlassified-Android/tree/jitpack as it should be the most up to date version.

To use it as a jitpack dependency check out https://jitpack.io/docs/ANDROID/#installing

@nmalcolm
Copy link

Yep, I'm using that already. Doesn't crash while encrypting, only discovered it by generating a signed APK, installing it manually, and checking the Android Studio log. Had others reproduce the issue too.

@andy9775
Copy link
Contributor Author

@nmalcolm I created a signed APK of the example project provided in the library using the jipack branch of my fork and I can't seem to reproduce the issue that your getting. I'm only getting an IllegalBlockSizeException which I need to address, but the data encrypts/decrypts without issue.

This is running on genymotion with android 6.0 as well as a galaxy s7 with 6.0.1

@ShaPOC
Copy link
Contributor

ShaPOC commented Jun 13, 2016

@nmalcolm Are you still having this issue with version 0.1.1? The QlassifiedCrypto: Could not encrypt this string. Stacktrace: java.security.NoSuchAlgorithmException: Provider SC does not provide RSA/NONE/PKCS1Padding? And only with signed APKs?

@nmalcolm
Copy link

@ShaPOC I am indeed. I'm baffled a signed APK doesn't work. Debugging works perfectly. Let me know if there's anything you need.

@zhibuyu
Copy link

zhibuyu commented Dec 8, 2016

检测到:中文 » 英语
My Mi5 may also have this problem, I tested all of our team 6.0 phone will quote ava. Lang. ClassCastException: android. Security. Keystore. AndroidKeyStoreRSAPrivateKey always be cast to Java security. Interfaces. RSAPrivateKey. 6.0 the following: no problem

@ghost
Copy link

ghost commented Mar 21, 2018

Im having this same issue when i turn minifyEnabled TRUE

Could not encrypt this string. Stacktrace: java.security.NoSuchAlgorithmException: Provider SC does not provide RSA/NONE/PKCS1Padding

Any ideas why?

@zhibuyu
Copy link

zhibuyu commented Mar 22, 2018

You can look at this.Compatible with 8.0:https://github.com/zhibuyu/KeyStoreEncryDemo

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

4 participants