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)
}