title: How to make X-Signature from private key? android
body: <p>What I need is from my private-key which looks like this</p>
  <pre><code>-----BEGIN PRIVATE KEY-----
  MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg0m4yLz+sdzZtBG9Q
  HQ9++wcfq1O4hOWgSBMb/A6eijyhRANCAAQeB0fBl2D7HZOKVBjpPiU2jabzNxQU
  ZYrJ+MSA3LpzZxmRk2JaFHNujjkJghQT19HHjg3Fnkb8Y9oIhB9neXBI
  -----END PRIVATE KEY-----
  </code></pre>
  <p>(I removed spaces, header and footer)</p>
  <p>Get X-Signature which is ECDSA (SHA256) signature as UTF-8 from X-Timestamp in DER format.
  Where X-Timestamp is Unix timestamp of current time without ms (like this 1623076761)</p>
  <p>X-Signature should look like this:</p>
  <pre><code>304402201429f934eedbf9b66b89dc88dbb45bec90a8819d8435acd6db90f6f00e3c80cc022032bc765dfb0d3203a92c3080e5fc71dc1b17ecf7c8089261be482fe30aa8a6bd
  </code></pre>
  <p>Kill me xD</p>
  <p>What I did is:</p>
  <pre><code>val privateKeyString = &quot;myKey&quot;
  val sigBytes: ByteArray = Base64Utils.decode(privateKeyString)
  
  val privateKeySpec = PKCS8EncodedKeySpec(sigBytes)
  val keyFactory = KeyFactory.getInstance(&quot;EC&quot;)
  
  val privateKey : PrivateKey = keyFactory.generatePrivate(privateKeySpec)
  </code></pre>
  <p>I got privateKey as PrivateKey object</p>
  <pre><code>val unixTime = System.currentTimeMillis() / 1000L
  </code></pre>
  <p>Got X-Timestamp</p>
  <pre><code>val signature: ByteArray? = Signature.getInstance(&quot;SHA256withECDSA&quot;).run {
      initSign(privateKey)
      update(&quot;$unixTime&quot;.toByteArray())
      sign()
  }
  
  val signatureResult : String = Base64Utils.encode(signature)
  </code></pre>
  <p>And then I did this. I don't really understand what should be <code>update(HERE.toByteArray())</code> and how to connect X-Timestamp with signature and how to make it in DER forma as well.</p>
  <p>I don't know xD. Is it really to solve this?</p>