MCPcopy
hub / github.com/FiloSottile/age / Encrypt

Function Encrypt

age.go:154–173  ·  view source on GitHub ↗

Encrypt encrypts a file to one or more recipients. Every recipient will be able to decrypt the file. Writes to the returned WriteCloser are encrypted and written to dst as an age file. The caller must call Close on the WriteCloser when done for the last chunk to be encrypted and flushed to dst.

(dst io.Writer, recipients ...Recipient)

Source from the content-addressed store, hash-verified

152// file. The caller must call Close on the WriteCloser when done for the last
153// chunk to be encrypted and flushed to dst.
154func Encrypt(dst io.Writer, recipients ...Recipient) (io.WriteCloser, error) {
155 fileKey := make([]byte, fileKeySize)
156 rand.Read(fileKey)
157
158 hdr, err := encryptHdr(fileKey, recipients...)
159 if err != nil {
160 return nil, err
161 }
162 if err := hdr.Marshal(dst); err != nil {
163 return nil, fmt.Errorf("failed to write header: %w", err)
164 }
165
166 nonce := make([]byte, streamNonceSize)
167 rand.Read(nonce)
168 if _, err := dst.Write(nonce); err != nil {
169 return nil, fmt.Errorf("failed to write nonce: %w", err)
170 }
171
172 return stream.NewEncryptWriter(streamKey(fileKey, nonce), dst)
173}
174
175// EncryptReader encrypts a file to one or more recipients. Every recipient will be
176// able to decrypt the file.

Callers 15

ExampleEncryptFunction · 0.92
TestEncryptDecryptX25519Function · 0.92
TestEncryptDecryptScryptFunction · 0.92
TestLabelsFunction · 0.92
TestScryptIdentityErrorsFunction · 0.92
TestDetachedHeaderFunction · 0.92
TestLabelsFunction · 0.92
TestNotFoundFunction · 0.92
TestPluginErrorFunction · 0.92

Calls 6

NewEncryptWriterFunction · 0.92
encryptHdrFunction · 0.85
streamKeyFunction · 0.70
ReadMethod · 0.45
MarshalMethod · 0.45
WriteMethod · 0.45

Tested by 15

ExampleEncryptFunction · 0.74
TestEncryptDecryptX25519Function · 0.74
TestEncryptDecryptScryptFunction · 0.74
TestLabelsFunction · 0.74
TestScryptIdentityErrorsFunction · 0.74
TestDetachedHeaderFunction · 0.74
TestLabelsFunction · 0.74
TestNotFoundFunction · 0.74
TestPluginErrorFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…