gpt4 book ai didi

c++ - 以 "simple"形式获取 RSA key

转载 作者:太空宇宙 更新时间:2023-11-04 08:25:12 24 4
gpt4 key购买 nike

如何获取 OpenSSL 生成的 RAW 格式的 key ?我的意思是我无法在任何在线工具中解码我的编码消息。我应该采取什么措施以适当的形式将我的 key 分发给其他客户端(在其他应用程序和网络应用程序中)?我的生成代码是:

void VS_CarrierNet::generateKeys()
{
m_rsa = RSA_generate_key(KEY_LENGTH, PUB_EXP, nullptr, nullptr);

// To get the C-string PEM form:
BIO *pri = BIO_new(BIO_s_mem());
BIO *pub = BIO_new(BIO_s_mem());

PEM_write_bio_RSAPrivateKey(pri, m_rsa, nullptr, nullptr, 0, nullptr, nullptr);
PEM_write_bio_RSAPublicKey(pub, m_rsa);

int pri_len = BIO_pending(pri);
int pub_len = BIO_pending(pub);

m_privateKey = new char[pri_len + 1];
m_publicKey = new char[pub_len + 1];

BIO_read(pri, m_privateKey, pri_len);
BIO_read(pub, m_publicKey, pub_len);

m_privateKey[pri_len] = '\0';
m_publicKey[pub_len] = '\0';

BIO_free_all(pub);
BIO_free_all(pri);

std::cout << "\n\n\n" << m_privateKey << "\n\n\n";
}

示例输出为:

-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEA1ZI9ucjBwMH2uePmln/xF3mjEIz0WcDQWeI9qZVDXckaFQhr vxDy7GKIuxqEOgcd4zWAGPsyn72i7v2bGxPHXcDdtSqImYk3p2oljBuuQCsbxAxR JXH54D6qUWBMsA5+4K9JVxd//RAhpE/pnXADP6z0O4IP+84m3PtBJjnmaIAOdnx0 iM61E1f7QnuaFWhG/K1lljlXCP30yIanKdr4c2iyF+XSF6SqE7ZcLTmFZAR9v+Gh 13vpMTwEWGJCUhJJN3Y/83VABWS+HGx7R7nI6IzWwxCcpoLxA67x+m/0WwMuiqDe MXIEDL6HMR7L2eEG80ef8+uSyYVFiGGyH+3AUQIBAwKCAQEAjmF+e9sr1dake+1E ZFVLZPvCCwii5oCK5pbTxmOCPoYRY1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ghl9Eu1rsQEAhQlZ0aCs7l9/v2+xIBmubzFqldjpODR1UPrj9O8 Kg3mJD7kG/2ql4dioxy3eTHGkzJBvTwfM/rBhY7rQ4X8ly8c/DvQ -----END RSA PRIVATE KEY-----

我应该以这种形式分发这个 key ,还是我需要它而不需要额外的文本和'\n'?我尝试删除页眉、页脚、'\n' 字符和 base64 解码。但这没有帮助。

最佳答案

简单的形式 - 包括页眉和页脚以及额外的换行符。大多数证书程序都可以很好地处理这种形式。

关于c++ - 以 "simple"形式获取 RSA key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com