title: Create EC private key from hex string
body: <p>I am wondering if this is a correct way to create PrivateKey object in Java from HEX string from this website: <a href="https://kjur.github.io/jsrsasign/sample/sample-ecdsa.html" rel="noreferrer">https://kjur.github.io/jsrsasign/sample/sample-ecdsa.html</a></p>
  
  <p>Create a BigInteger from a HEX String:</p>
  
  <pre><code>BigInteger priv = new BigInteger(privateKeyFromSite, 16);
  </code></pre>
  
  <p>And pass to this method:</p>
  
  <pre><code>import java.math.BigInteger;
  import java.security.KeyFactory;
  import java.security.NoSuchAlgorithmException;
  import java.security.PrivateKey;
  import java.security.spec.InvalidKeySpecException;
  
  import org.bouncycastle.jce.ECNamedCurveTable;
  import org.bouncycastle.jce.spec.ECParameterSpec;
  import org.bouncycastle.jce.spec.ECPrivateKeySpec;
  
  
  public static PrivateKey getPrivateKeyFromECBigIntAndCurve(BigInteger s, String curveName) {
  
      ECParameterSpec ecParameterSpec = ECNamedCurveTable.getParameterSpec(curveName);
  
      ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(s, ecParameterSpec);
      try {
          KeyFactory keyFactory = KeyFactory.getInstance(EC);
          return keyFactory.generatePrivate(privateKeySpec);
      } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
          e.printStackTrace();
          return null;
      }
  }
  </code></pre>