Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Encoders = make(map[EndeType]AsymmetricEncoder, 2) Decoders = make(map[EndeType]AsymmetricDecoder, 2) )
以下值只会在init中进行修改,所以认为是安全的
View Source
var (
Ecdhs = make(map[string]Ecdh, 2)
)
以下值只会在init中进行修改,所以认为是安全的
Functions ¶
func SignEd25519 ¶
func SignEd25519(privateKey ed25519.PrivateKey, hash []byte) (signature []byte, publicBytes []byte)
func ToSigningHash ¶
Types ¶
type AsymmetricDecoder ¶
type AsymmetricDecoder interface { // EcdhDecode // EndeData中已经包含peersKey,所以没有出现在参数中 EcdhDecode(privateKey crypto.PrivateKey, cipher *EndeData) (plain EndeData, err error) }
func GetAsymmetricDecoder ¶
func GetAsymmetricDecoder(data *EndeData) AsymmetricDecoder
type AsymmetricEncoder ¶
type AsymmetricEncoder interface {
EcdhEncode(privateKey crypto.PrivateKey, peersKey crypto.PublicKey, plain *EndeData) (cipher EndeData, err error)
}
func GetAsymmetricEncoder ¶
func GetAsymmetricEncoder(data *EndeData) AsymmetricEncoder
type CurveParameters ¶
type Ecdh ¶
type Ecdh interface { // GenerateKey generates a private/public key pair using entropy from rand. // If rand is nil, crypto/rand.Reader will be used. GenerateKey(rand io.Reader) (private crypto.PrivateKey, public crypto.PublicKey, err error) // Parameters returns the curve parameters - like the field size. Parameters() CurveParameters // PublicKey returns the public key corresponding to the given private one. PublicKey(private crypto.PrivateKey) (public crypto.PublicKey, err error) // ComputeSecret returns the secret value computed from the given private key // and the peers public key. ComputeSecret(private crypto.PrivateKey, peersPublic crypto.PublicKey) (secret []byte, err error) PublicKeyToBytes(publicKey crypto.PublicKey) (key []byte, err error) PrivateKeyToBytes(privateKey crypto.PrivateKey) (key []byte, err error) BytesToPublicKey(keyBytes []byte) (publicKey crypto.PublicKey, err error) BytesToPrivateKey(keyBytes []byte) (privateKey crypto.PrivateKey, err error) }
Ecdh is the interface defining all functions necessary for ECDH.
type EndeData ¶
type EndeData struct { //加密时使用的公钥 PublicKey []byte EndeType EndeType //对Body的签名, Signature []byte //ed25519不能从签名出计算出公钥,所以需要来验证签名。在使用中双方也可以约定公钥,并不一定要存放在字段中 SignedPublicKey []byte //true数据已加密 EnData bool //数据 Body []byte }
func DecodeData ¶
func EncodeData ¶
func (EndeData) MarshalJSON ¶
func (*EndeData) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.