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

spongycastle fails in android API < 21 #47

Open
eehlers opened this issue May 29, 2019 · 2 comments
Open

spongycastle fails in android API < 21 #47

eehlers opened this issue May 29, 2019 · 2 comments

Comments

@eehlers
Copy link

eehlers commented May 29, 2019

i am trying to run some spongycastle code in android:

        try {
            Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
            ECGenParameterSpec spec = new ECGenParameterSpec("P-256");
            KeyPairGenerator generator = KeyPairGenerator.getInstance("ECDSA", "SC");
            generator.initialize(spec, new SecureRandom());
            KeyPair keyPair = generator.generateKeyPair();
            ECPublicKey publicKey = (ECPublicKey) keyPair.getPublic();
            ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate();
            String publicKeyStr = publicKey.getW().getAffineX().toString() + ":" + publicKey.getW().getAffineY().toString();
            Log.d(TAG, publicKeyStr);
            Calendar c = Calendar.getInstance();
            Date d0 = c.getTime();
            c.add(Calendar.DATE, 1);
            Date expiry = c.getTime();
            String token = Jwts.builder()
                    .setIssuedAt(d0)
                    .setSubject("00000000-0000-0000-0000-000000000001")
                    .setExpiration(expiry)
                    .signWith(privateKey, SignatureAlgorithm.ES256).compact();
            Log.d(TAG, token);
        } catch (Exception e) {
            Log.d(TAG, e.toString());
        }

in API version 21+, it works as expected.

in API version 18, it works in debug. in release, it fails in function generator.generateKeyPair() with java.lang.IllegalArgumentException: Invalid point.

in API version 16, it fails in function Jwts.builder().signWith() with io.jsonwebtoken.security.SignatureException: Invalid Elliptic Curve PrivateKey. can't recognise key type in ECDSA based signer.

any idea what i am doing wrong?

@SahilAshar
Copy link

I'm assuming you're doing all this on the Android Studio Emulator? Can you try testing this code out on Android 19 and seeing what the debug + production spits out?

@nienienienie
Copy link

any news on that?

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

3 participants