title: How can I get java.security.PrivateKey from 32 byte raw private key ? (Secp256k1 Algorithm)
body: <p>I'm trying to get PrivateKey Object from 32-byte raw private key that I got by useing getS() method. I used ECDSA secp256k1 algorithm at bouncy castle library to generate a key pair.</p>
  
  <p>Below is the way that I got 32-byte private key in byte array, and I would like to reverse this process to get PrivateKey object from the 32-byte private key. </p>
  
  <p>Can anyone please help me out with this? I'd really appreciate it.</p>
  
  <pre class="lang-java prettyprint-override"><code>PrivateKey prvKey;
  
  public byte[] getPrivateKey() {
          ECPrivateKey ecPrv = (ECPrivateKey) this.prvKey;
          byte[] prv = ecPrv.getS().toByteArray();
          if (prv[0] == 0) {
              byte[] rslt = new byte[prv.length - 1];
              System.arraycopy(prv, 1, rslt, 0, prv.length - 1);
              return rslt;
          } else {
              return prv;
          }
      }
  </code></pre>