Documentation
¶
Overview ¶
Package crypto
@author: xwc1125
Package crypto ¶
@author: xwc1125
Package crypto ¶
@author: xwc1125
Index ¶
- Constants
- Variables
- func BasicEquals(k1, k2 protocol.Key) bool
- func CreateAddress(b types.Address, nonce uint64) types.Address
- func CreateAddress2(b types.Address, salt [32]byte, code []byte) types.Address
- func CryptoLabel(cryptoType CryptoType) string
- func IDFromPrivateKey(sk protocol.PrivKey) (models.NodeID, error)
- func IDFromPublicKey(pk protocol.PubKey) (models.NodeID, error)
- func PubkeyToAddress(pk crypto.PublicKey) (types.Address, error)
- func RecoverPubKey(data []byte, signResult *signature.SignResult) (crypto.PublicKey, error)
- func Sign(data []byte, prv crypto.PrivateKey) (sig *signature.SignResult, err error)
- func Verify(data []byte, signResult *signature.SignResult) (bool, error)
- type CryptoType
- type JsonKey
- type KeyPair
- func GenerateKeyPair(cryptoType CryptoType) (*KeyPair, error)
- func ParsePrivateKeyJsonKey(jsonPrv JsonKey) (*KeyPair, error)
- func ParsePrivateKeyPem(keyPemBytes, certPemBytes []byte, pwd []byte) (privateKey *KeyPair, err error)
- func ParsePublicKeyJsonKey(jsonKey JsonKey) (*KeyPair, error)
- func ParsePublicKeyPem(keyPemBytes []byte) (*KeyPair, error)
- func PrivKeyWithDer(der []byte) (*KeyPair, error)
- func PubKeyWithDer(der []byte) (*KeyPair, error)
- func ToPrivateKey(prvKey crypto.PrivateKey) (*KeyPair, error)
- func ToPublicKey(pubKey crypto.PublicKey) (*KeyPair, error)
- func UnmarshalPrivateKey(jsonPrvData []byte) (*KeyPair, error)
- func UnmarshalPublicKey(jsonKeyBytes []byte) (*KeyPair, error)
Constants ¶
Variables ¶
var ( UNKNOWN = CryptoType{"UNKNOWN", -1} RSA = CryptoType{"RSA", KeyType_RSA} Ed25519 = CryptoType{"Ed25519", KeyType_Ed25519} P256 = CryptoType{"P-256", KeyType_P256} P384 = CryptoType{"P-384", KeyType_P384} P521 = CryptoType{"P-521", KeyType_P521} S256 = CryptoType{"S-256", KeyType_S256} SM2P256 = CryptoType{"SM2-P-256", KeyType_SM2} )
var ( ErrRsaKeyTooSmall = errors.New("rsa key too small") FormatKeyType = "unsupported the key type:%d" FormatKeyName = "unsupported the key name:%s" )
var ( FormatUnsupported = "unsupported cure crypto. type:%d, name:%s" ErrPrivate = errors.New("unsupported private key type") ErrPublic = errors.New("unsupported public key type") )
var (
MinRsaKeyBits = 1024
)
Functions ¶
func CreateAddress ¶
CreateAddress 根据给定的地址及nonce生成新地址
func CreateAddress2 ¶
CreateAddress2 根据给定地址,salt和code生成新的地址
func IDFromPrivateKey ¶
IDFromPrivateKey 通过私钥获取PeerID
func IDFromPublicKey ¶
IDFromPublicKey 根据公钥生成PeerID
func PubkeyToAddress ¶
PubkeyToAddress 根据公钥生成地址
func RecoverPubKey ¶
RecoverPubKey 从签名中恢复公钥
func Sign ¶
func Sign(data []byte, prv crypto.PrivateKey) (sig *signature.SignResult, err error)
Sign 签名数据[节点之间的签名]
Types ¶
type CryptoType ¶
CryptoType crypto type
func ParseKeyName ¶
func ParseKeyName(keyName string) (CryptoType, error)
ParseKeyName 将keyName转换为CryptoType
func ParseKeyType ¶
func ParseKeyType(keyType int32) (CryptoType, error)
ParseKeyType 将int32转换为对应的CryptoType
type JsonKey ¶
type JsonKey struct { Type int32 `json:"type" mapstructure:"type"` Data []byte `json:"data" mapstructure:"data"` }
JsonKey key对象
func MarshalPrivateKey ¶
func MarshalPrivateKey(prvKey crypto.PrivateKey) (*JsonKey, error)
MarshalPrivateKey 私钥转换为JsonKey,data尽可能x509格式
func MarshalPrivateKeyX509 ¶
func MarshalPrivateKeyX509(prvKey crypto.PrivateKey) (*JsonKey, error)
func MarshalPublicKey ¶
MarshalPublicKey 将公钥转换为jsonKey格式,jsonKey.data=x509格式
func (*JsonKey) Deserialize ¶
func (*JsonKey) SerializeUnsafe ¶
type KeyPair ¶
type KeyPair struct { CryptoType CryptoType Prv crypto.PrivateKey Pub crypto.PublicKey }
KeyPair 密钥对
func GenerateKeyPair ¶
func GenerateKeyPair(cryptoType CryptoType) (*KeyPair, error)
GenerateKeyPair 生成p2p对应的公私钥
func ParsePrivateKeyJsonKey ¶
ParsePrivateKeyJsonKey 解析jsonKey为对象
func ParsePrivateKeyPem ¶
func ParsePrivateKeyPem(keyPemBytes, certPemBytes []byte, pwd []byte) (privateKey *KeyPair, err error)
ParsePrivateKeyPem parse key pem to privateKey
func ParsePublicKeyJsonKey ¶
ParsePublicKeyJsonKey 解析jsonKey为对象
func ParsePublicKeyPem ¶
ParsePublicKeyPem parse key pem to publicKey
func PrivKeyWithDer ¶
PrivKeyWithDer 将der格式转换为crypto.PrivateKey
func PubKeyWithDer ¶
PubKeyWithDer 将der格式转换为crypto.PublicKey
func ToPrivateKey ¶
func ToPrivateKey(prvKey crypto.PrivateKey) (*KeyPair, error)
ToPrivateKey 将原生的PrivateKey转换为protocol.PrivateKey
func ToPublicKey ¶
ToPublicKey 将原生的PublicKey转换为protocol.PublicKey
func UnmarshalPrivateKey ¶
UnmarshalPrivateKey 解析JsonKeyBytes成对象,将x509格式转换为p2p私钥
func UnmarshalPublicKey ¶
UnmarshalPublicKey 解析jsonKeyBytes成对象,将x509格式转换为p2p公钥