title: Tutorial of ECDSA algorithm to sign a string
body: <p>Can you help me to find a simple tutorial of how sign a string using ECDSA algorithm in java. But without using any third-party libraries like bouncycastle. Just JDK 7. I found it difficult to search a simple example, I'm new to cryptography.</p>
  
  <hr>
  
  <pre><code>import java.io.*;
  import java.security.*;
  
  public class GenSig {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          /*
           * Generate a DSA signature
           */
  
          try {
  
              /*
               * Generate a key pair
               */
  
              KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
              SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
  
              keyGen.initialize(1024, random);
  
              KeyPair pair = keyGen.generateKeyPair();
              PrivateKey priv = pair.getPrivate();
              PublicKey pub = pair.getPublic();
  
              /*
               * Create a Signature object and initialize it with the private key
               */
  
              Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
  
              dsa.initSign(priv);
  
              String str = "This is string to sign";
              byte[] strByte = str.getBytes();
              dsa.update(strByte);
  
              /*
               * Now that all the data to be signed has been read in, generate a
               * signature for it
               */
  
              byte[] realSig = dsa.sign();
              System.out.println("Signature: " + new String(realSig));
  
  
          } catch (Exception e) {
              System.err.println("Caught exception " + e.toString());
          }
      }
  }
  </code></pre>
  
  <p>How to modify it for ECDSA?</p>