MCPcopy Create free account
hub / github.com/KOSASIH/skybridge / Encrypt

Method Encrypt

src/crypto/encryption/encryption.go:23–38  ·  view source on GitHub ↗
(plaintext []byte)

Source from the content-addressed store, hash-verified

21}
22
23func (e *Encryption) Encrypt(plaintext []byte) ([]byte, error) {
24 block, err := aes.NewCipher(e.key)
25 if err != nil {
26 return nil, err
27 }
28 gcm, err := cipher.NewGCM(block)
29 if err != nil {
30 return nil, err
31 }
32 nonce := make([]byte, gcm.NonceSize())
33 if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
34 return nil, err
35 }
36 ciphertext := gcm.Seal(nonce, nonce, plaintext, nil)
37 return ciphertext, nil
38}
39
40func (e *Encryption) Decrypt(ciphertext []byte) ([]byte, error) {
41 block, err := aes.NewCipher(e.key)

Callers 2

EncryptBase64Method · 0.95

Calls

no outgoing calls

Tested by 1