Closed itachiliu closed 3 years ago
You can create a libp2p host with an existing private key using the Identity(sk crypto.PrivKey)
function. If you choose to save and reload the private keys from disk that will work.
You can create a libp2p host with an existing private key using the
Identity(sk crypto.PrivKey)
function. If you choose to save and reload the private keys from disk that will work.
Thank you for your reply,I am a newbie. how do I generate a fixed PrivKey and preserve it?
@itachiliu you can use the libraries in go-libp2p-core/crypto to generate keys (e.g. crypto.GenerateKeyPair(crypto.Ed25519, 0)
, or crypto.GenerateKeyPair(crypto.RSA, 2048)
) , marshal the private key (i.e. crypto.MarshalPrivateKey(priv)
) and then store the bytes somewhere.
You can then unmarshal your private key using crypto.UnmarshalPrivateKey()
@itachiliu you can use the libraries in go-libp2p-core/crypto to generate keys (e.g.
crypto.GenerateKeyPair(crypto.Ed25519, 0)
, orcrypto.GenerateKeyPair(crypto.RSA, 2048)
) , marshal the private key (i.e.crypto.MarshalPrivateKey(priv)
) and then store the bytes somewhere.You can then unmarshal your private key using
crypto.UnmarshalPrivateKey()
Thx again,it works.😄
Chat - with - rendezvous example, when I start a new node, generates a new node ID, such as QmR4j8pDzvy9JMjmXeYhcFXypjZJBKGWGZHBaittyy41is, but shut down the node (CTR + c), and then restart, node ID of the change, I want to make the node ID remains the same, have what way?