正确产生比特币地址

时间:2018-10-07 20:02:48

标签: cryptography cout chilkat

想了解在比特币地址生成中应该使用哪些变量和格式来正确使用加密算法。

我将Chilkat库用于ecdsa和成熟的160 sha256加密函数。

CkPrng fortuna;
const char *entropy = fortuna.getEntropy(32, "base64");
fortuna.AddEntropy(entropy, "base64");

// cout << string(entropy) << endl;
// 0210qtm3T9YoNlmMjRpiyzgVnawK2H6f1dusP1iP+38=

CkEcc ecc;

//  Generate a random ECC private key on the secp256r1 curve.
//  Chilkat also supports other curves, such as secp384r1, secp521r1, and secp256k1.

CkPrivateKey *privKey = ecc.GenEccKey("secp256r1", fortuna);
if (privKey == 0) {
    cout << ecc.lastErrorText() << "\r\n";
    return;
}

success = privKey->SavePkcs8EncryptedPemFile(privatePass.c_str(), privatePath.c_str());
if (success != true) {
    cout << privKey->lastErrorText() << "\r\n";
    return trust;
}

CkPublicKey *pubKey = privKey->GetPublicKey();

delete privKey;

bool bPreferPkcs1 = false;
success = pubKey->SavePemFile(bPreferPkcs1, publicPath.c_str());
if (success != true) {
    cout << pubKey->lastErrorText() << "\r\n";
    return trust;
}

CkJsonObject ckJson;
ckJson.Load(jwk);
ckJson.put_EmitCompact(false);

CkString xValue;
ckJson.StringOf("x", xValue);

CkString yValue;
ckJson.StringOf("y", yValue);

string ecdsaStr = string(xValue.getString()) + string(yValue.getString());

const char *sha256Str = 0;
crypt.put_HashAlgorithm("sha256");

sha256Str = crypt.hashStringENC(ecdsaStr.c_str());

cout << "sha256: " << sha256Str << "\r\n";
// zu68LKfjotv+nm2qX4YROFajICbf2x1hy92YLixM8Q=

首先我应该使用X,Y值生成sha256字符。

第二个我得到了奇怪的sha256输出字符串,但是在原始比特币地址示例中是:0b7c28c9b7290c98d7438e70b3d3f7c848fbd7d1dc194ff83f4f7cc9b1378e98

请帮助我使用正确的数据和类似于比特币示例的输出。

0 个答案:

没有答案