CSecret CKey::GetSecret(bool &fCompressed) const { CSecret vchRet; vchRet.resize(32); const BIGNUM *bn = EC_KEY_get0_private_key(pkey); int nBytes = BN_num_bytes(bn); if (bn == NULL) throw key_error("CKey::GetSecret() : EC_KEY_get0_private_key failed"); int n=BN_bn2bin(bn,&vchRet[32 - nBytes]); if (n != nBytes) throw key_error("CKey::GetSecret(): BN_bn2bin failed"); fCompressed = fCompressedPubKey; return vchRet; }
void dumpKeyInfo(uint256 privkey) { CSecret secret; secret.resize(32); memcpy(&secret[0], &privkey, 32); vector<unsigned char> sec; sec.resize(32); memcpy(&sec[0], &secret[0], 32); printf(" * secret (hex): %s\n", HexStr(sec).c_str()); for (int nCompressed=0; nCompressed<2; nCompressed++) { bool fCompressed = nCompressed == 1; printf(" * %s:\n", fCompressed ? "compressed" : "uncompressed"); CCosmoscoinSecret bsecret; bsecret.SetSecret(secret, fCompressed); printf(" * secret (base58): %s\n", bsecret.ToString().c_str()); CKey key; key.SetSecret(secret, fCompressed); vector<unsigned char> vchPubKey = key.GetPubKey(); printf(" * pubkey (hex): %s\n", HexStr(vchPubKey).c_str()); printf(" * address (base58): %s\n", CCosmoscoinAddress(vchPubKey).ToString().c_str()); } }