Documentation ¶
Overview ¶
Package nodekey
@author: xwc1125
Package nodekey ¶
@author: xwc1125
Package nodekey ¶
@author: xwc1125
Package nodekey ¶
@author: xwc1125
Package nodekey ¶
@author: xwc1125
Package nodekey ¶
@author: xwc1125
Index ¶
- Constants
- Variables
- func IDFromPrivateKey(sk protocol.PrivKey) (models.NodeID, error)
- func IDFromPublicKey(pk protocol.PubKey) (models.NodeID, error)
- func IdFromPub(pub crypto.PublicKey) (models.NodeID, error)
- func MarshalPrivateKey(prvKey crypto.PrivateKey) (*pcrypto.JsonKey, error)
- func MarshalPrivateKeyX509(prvKey crypto.PrivateKey) (*pcrypto.JsonKey, error)
- func MarshalPublicKey(ePub crypto.PublicKey) (*pcrypto.JsonKey, error)
- func MarshalPublicKeyX509(ePub crypto.PublicKey) (*pcrypto.JsonKey, error)
- func NewNodeKey(rootCtx context.Context, opts ...option) (protocol.NodeKey, error)
- func RecoverId(data []byte, signResult *signature.SignResult) (models.NodeID, error)
- func SavePrivateKey(prvKey *PrivateKey, fileType FileType, prvKeyFile string, pubKeyFile string, ...) error
- func SaveToPemFile(prvKey *PrivateKey, prvKeyFile string, pubKeyFile string, pwd string) error
- func Sign(data []byte, prv crypto.PrivateKey) (sig *signature.SignResult, err error)
- func Verify(data []byte, signResult *signature.SignResult) (bool, error)
- func WithConfig(config protocol.Config) option
- type FileType
- type PrivateKey
- func GenerateKeyPair(cryptoType pcrypto.CryptoType) (*PrivateKey, error)
- func LoadPrivateKey(fileType FileType, prvKeyFile string, pubKeyFile string, pwd string, ...) (*PrivateKey, error)
- func NewPrivateKey(prv crypto.PrivateKey) (*PrivateKey, error)
- func ParsePrivateKeyPem(keyPemBytes, certPemBytes []byte, pwd []byte) (privateKey *PrivateKey, err error)
- func ToPrivateKey(prvKey crypto.PrivateKey) (*PrivateKey, error)
- func UnmarshalPrivateKey(jsonPrvData []byte) (*PrivateKey, error)
- func (p *PrivateKey) Equals(key protocol.Key) bool
- func (p *PrivateKey) GetPublic() protocol.PubKey
- func (p *PrivateKey) Hash() func() hash.Hash
- func (p *PrivateKey) ID() (models.NodeID, error)
- func (p *PrivateKey) Marshal() ([]byte, error)
- func (p *PrivateKey) MarshalJSON() ([]byte, error)
- func (p *PrivateKey) Raw() ([]byte, error)
- func (p *PrivateKey) Sign(data []byte) (*signature.SignResult, error)
- func (p *PrivateKey) Type() protocol.KeyType
- func (p *PrivateKey) Unmarshal(input []byte) error
- func (p *PrivateKey) UnmarshalJSON(bytes []byte) error
- type PublicKey
- func LoadPublicKey(pubFile string) (*PublicKey, error)
- func LoadPublicKeyFromBytes(pubBytes []byte) (*PublicKey, error)
- func NewPublicKey(pub crypto.PublicKey) (*PublicKey, error)
- func ParsePublicKeyPem(keyPemBytes []byte) (*PublicKey, error)
- func ToPublicKey(pubKey crypto.PublicKey) (*PublicKey, error)
- func UnmarshalPublicKey(jsonKeyBytes []byte) (*PublicKey, error)
- func (ePub *PublicKey) Equals(key protocol.Key) bool
- func (ePub *PublicKey) Hash() func() hash.Hash
- func (ePub *PublicKey) Marshal() ([]byte, error)
- func (ePub *PublicKey) Raw() ([]byte, error)
- func (ePub *PublicKey) Type() protocol.KeyType
- func (ePub *PublicKey) Unmarshal(input []byte) error
- func (ePub *PublicKey) Verify(data []byte, signResult *signature.SignResult) (bool, error)
Constants ¶
View Source
const ( FileType_Hex = "hex" FileType_Base64 = "base64" FileType_Pem = "pem" FileType_P12 = "p12" )
Variables ¶
View Source
var (
ErrFileType = errors.New("unsupported the fileType")
)
Functions ¶
func IDFromPrivateKey ¶
IDFromPrivateKey 通过私钥获取PeerID
func IDFromPublicKey ¶
IDFromPublicKey 根据公钥生成PeerID
func MarshalPrivateKey ¶
func MarshalPrivateKey(prvKey crypto.PrivateKey) (*pcrypto.JsonKey, error)
func MarshalPrivateKeyX509 ¶
func MarshalPrivateKeyX509(prvKey crypto.PrivateKey) (*pcrypto.JsonKey, error)
func MarshalPublicKeyX509 ¶
func NewNodeKey ¶
NewNodeKey 创建新的NodeKey
func SavePrivateKey ¶
func SavePrivateKey(prvKey *PrivateKey, fileType FileType, prvKeyFile string, pubKeyFile string, pwd string) error
SavePrivateKey 保存节点私钥到nodekey文件
func SaveToPemFile ¶
func SaveToPemFile(prvKey *PrivateKey, prvKeyFile string, pubKeyFile string, pwd string) error
func Sign ¶
func Sign(data []byte, prv crypto.PrivateKey) (sig *signature.SignResult, err error)
Sign 签名数据[节点之间的签名]
func Verify ¶
func Verify(data []byte, signResult *signature.SignResult) (bool, error)
Verify 验证签名内容 sigBytes 是signResult的bytes值
func WithConfig ¶
Types ¶
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey 私钥,实现p2p的私钥接口
func GenerateKeyPair ¶
func GenerateKeyPair(cryptoType pcrypto.CryptoType) (*PrivateKey, error)
GenerateKeyPair 生成p2p对应的公私钥
func LoadPrivateKey ¶
func LoadPrivateKey(fileType FileType, prvKeyFile string, pubKeyFile string, pwd string, args ...string) (*PrivateKey, error)
LoadPrivateKey 从指定路径下加载nodekey文件
func NewPrivateKey ¶
func NewPrivateKey(prv crypto.PrivateKey) (*PrivateKey, error)
NewPrivateKey 根据原生私钥创建一个自有私钥
func ParsePrivateKeyPem ¶
func ParsePrivateKeyPem(keyPemBytes, certPemBytes []byte, pwd []byte) (privateKey *PrivateKey, err error)
ParsePrivateKeyPem parse key pem to privateKey
func ToPrivateKey ¶
func ToPrivateKey(prvKey crypto.PrivateKey) (*PrivateKey, error)
ToPrivateKey 将原生的PrivateKey转换为protocol.PrivateKey
func UnmarshalPrivateKey ¶
func UnmarshalPrivateKey(jsonPrvData []byte) (*PrivateKey, error)
func (*PrivateKey) Hash ¶
func (p *PrivateKey) Hash() func() hash.Hash
func (*PrivateKey) Marshal ¶
func (p *PrivateKey) Marshal() ([]byte, error)
func (*PrivateKey) MarshalJSON ¶
func (p *PrivateKey) MarshalJSON() ([]byte, error)
func (*PrivateKey) Sign ¶
func (p *PrivateKey) Sign(data []byte) (*signature.SignResult, error)
Sign 签名data
func (*PrivateKey) Type ¶
func (p *PrivateKey) Type() protocol.KeyType
func (*PrivateKey) Unmarshal ¶
func (p *PrivateKey) Unmarshal(input []byte) error
func (*PrivateKey) UnmarshalJSON ¶
func (p *PrivateKey) UnmarshalJSON(bytes []byte) error
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey 公钥,实现p2p的公钥接口
func LoadPublicKey ¶
func LoadPublicKeyFromBytes ¶
func NewPublicKey ¶
NewPublicKey 原生公钥转自有公钥
func ParsePublicKeyPem ¶
ParsePublicKeyPem parse key pem to publicKey
func ToPublicKey ¶
ToPublicKey 将原生的PublicKey转换为protocol.PublicKey
func UnmarshalPublicKey ¶
Click to show internal directories.
Click to hide internal directories.