Question

I am trying to write an ECDSA java algorithm to implement in android phones. The data is parsed using NFC. That's what the write(id+"?"+nama+"?"+signature+"?"+saldo, mytag) is for.

Here is what I wrote:

       String id = null;
       String nama = null;
       String saldo = "50000";  

       if(edNIM.getText()!=null && edNama.getText()!=null){
                  id = edNIM.getText().toString();
          nama = edNama.getText().toString();
       }
        String C = id+"?"+nama+"?"+saldo;
        String signature = ECKeyGen.Generate(C);

        write (id+"?"+nama+"?"+signature+"?"+saldo, mytag);                 

            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), "Error Writing to Tag", Toast.LENGTH_LONG ).show();
                e.printStackTrace();
            } catch (FormatException e) {
                Toast.makeText(getApplicationContext(), "Error Writing to Tag" , Toast.LENGTH_LONG ).show();
                e.printStackTrace();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }

While the ECKeyGen.Generate(C) is

public static String Generate(String x) throws Exception{
    KeyPairGenerator kpg;
    kpg = KeyPairGenerator.getInstance("EC","SunEC");
    ECGenParameterSpec ecsp;
    ecsp = new ECGenParameterSpec("secp192r1");
    kpg.initialize(ecsp);

    KeyPair kp = kpg.genKeyPair();
    PrivateKey privKey = kp.getPrivate();

    Signature ecdsa;
    ecdsa = Signature.getInstance("SHA1withECDSA","SunEC");
    ecdsa.initSign(privKey);
    byte[] baText = x.getBytes("UTF-8");

    ecdsa.update(baText);
    byte[] baSignature = ecdsa.sign();
    String signature = (new BigInteger(1,baSignature).toString(16)).toUpperCase();
    return signature;
}

The problem is, when I debug the program, it keeps skipping the code from String signature = ECKeyGen.Generate(C) to catch(Exception).

The log says java.security.NoSuchProviderException: SunEC.

What does this mean?

Can someone explain to me where my mistake is?

Was it helpful?

Solution

"SunEC" is a provider containing an implementation and not part of the official API. That provider is Sun/Oracle specific and certainly not available on Android. Try SpongyCastle instead, and don't specify providers unless you really need to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top