user12533: I have a BigInteger that represents a private key. How can I get that private key as a base58 encoded string? The following pseudo code does not work properly:
base58.encode(bigInt.toByteArray) 
// yields a string that differs from given bigInt's private key

UPDATE  
def fullDoubleSha(bytes: ArrayOfByte) = {
  val digestSha = MessageDigest getInstance "SHA-256"
  digestSha digest digestSha.digest(bytes)
}

def getPrivBytes(key: BigInteger) = key.toByteArray match { case keyBytes =>
  val res = if (keyBytes.head == 0) keyBytes drop 1 else keyBytes
  new Array(32 - res.length) ++ res
}

def privBytesToWif(vs: ArrayOfByte) = {
  val rawPrivKey = Array(0x80.toByte) ++ vs
  rawPrivKey ++ fullDoubleSha(rawPrivKey).take(4)
}


user5757: The base58 private key format includes an SHA256-based checksum.  See this answer for details (disregard the part of the question where the private key itself is the SHA256 hash of some other data).  

12533: <p>I have a <code>BigInteger</code> that represents a private key. How can I get that private key as a base58 encoded string? The following pseudo code does not work properly:</p>

<pre><code>base58.encode(bigInt.toByteArray) 
// yields a string that differs from given bigInt's private key
</code></pre>

<p>UPDATE  </p>

<pre><code>def fullDoubleSha(bytes: ArrayOfByte) = {
  val digestSha = MessageDigest getInstance "SHA-256"
  digestSha digest digestSha.digest(bytes)
}

def getPrivBytes(key: BigInteger) = key.toByteArray match { case keyBytes =&gt;
  val res = if (keyBytes.head == 0) keyBytes drop 1 else keyBytes
  new Array(32 - res.length) ++ res
}

def privBytesToWif(vs: ArrayOfByte) = {
  val rawPrivKey = Array(0x80.toByte) ++ vs
  rawPrivKey ++ fullDoubleSha(rawPrivKey).take(4)
}
</code></pre>
 5757: <p>The base58 private key format includes an SHA256-based checksum.  See <a href="https://bitcoin.stackexchange.com/a/8249/5757">this answer</a> for details (disregard the part of the question where the private key itself is the SHA256 hash of some other data).  </p>
