MCPcopy Create free account
hub / github.com/chanify/chanify / Encrypt

Method Encrypt

crypto/crypto.go:102–113  ·  view source on GitHub ↗

Encrypt data with public key

(data []byte)

Source from the content-addressed store, hash-verified

100
101// Encrypt data with public key
102func (k *PublicKey) Encrypt(data []byte) ([]byte, error) {
103 seckey, _ := ecdsa.GenerateKey(k.Curve, rand.Reader)
104 Z, _ := calcSharedKey(seckey, &k.PublicKey)
105 X := elliptic.Marshal(k.Curve, seckey.X, seckey.Y)
106 K := x963KDF(Z, X, sha256.New)
107 key := K[:eciesKeyLen]
108 nonce := K[eciesKeyLen:]
109 block, _ := aes.NewCipher(key)
110 aesgcm, _ := cipher.NewGCMWithNonceSize(block, eciesKeyLen)
111 cipherData := aesgcm.Seal(nil, nonce, data, nil)
112 return append(X, cipherData...), nil
113}
114
115// GetPublicKey from secret key
116func (k *SecretKey) GetPublicKey() *PublicKey {

Callers 3

TestCryptoFunction · 0.80
TestKeyFailedFunction · 0.80
PublicKeyEncryptMethod · 0.80

Calls 3

calcSharedKeyFunction · 0.85
x963KDFFunction · 0.85
MarshalMethod · 0.80

Tested by 2

TestCryptoFunction · 0.64
TestKeyFailedFunction · 0.64