eos代码阅读笔记03- 公钥私钥匙生成

只运行cleos,不运行节点nodeos,就能够生成私钥。私钥再生成公钥。

公钥私钥的生成是不上链条的。账号和权限的创建、修改是通过交易的方式上链的。

eos/programs/cleos/main.cpp 的main函数里

 // create key
   auto create_key = create->add_subcommand("key", localized("Create a new keypair and print the public and private keys"))->set_callback( [&r1](){
      if( r1 ) {
         auto pk    = private_key_type::generate_r1();
         auto privs = string(pk);
         auto pubs  = string(pk.get_public_key());
         std::cout << localized("Private key: ${key}", ("key",  privs) ) << std::endl;
         std::cout << localized("Public key: ${key}", ("key", pubs ) ) << std::endl;
      } else {
         auto pk    = private_key_type::generate();
         auto privs = string(pk);
         auto pubs  = string(pk.get_public_key());私钥生成公钥
         std::cout << localized("Private key: ${key}", ("key",  privs) ) << std::endl;
         std::cout << localized("Public key: ${key}", ("key", pubs ) ) << std::endl;
      }
   });

libraries/fc/include/fc/crypto/private_key.hpp 通过椭圆曲线加密的方式生成

 template< typename KeyType = ecc::private_key_shim > 椭圆曲线加密
         static private_key generate() {
            return private_key(storage_type(KeyType::generate()));
         }

社区也提供了公私钥匙生成工具  私钥和公钥


可以使用一个自己方便记忆的单词数字生成公私钥。

源代码 https://github.com/eostea/eos-generate-key


猜你喜欢

转载自blog.csdn.net/zfdabc_ok/article/details/80854052