MCPcopy
hub / github.com/kopia/kopia / Encrypt

Function Encrypt

internal/blobcrypto/blob_crypto.go:44–66  ·  view source on GitHub ↗

Encrypt encrypts the given data using crypter-defined key and returns a name that should be used to save the blob in the repository.

(c Crypter, payload gather.Bytes, prefix, suffix blob.ID, output *gather.WriteBuffer)

Source from the content-addressed store, hash-verified

42// Encrypt encrypts the given data using crypter-defined key and returns a name that should
43// be used to save the blob in the repository.
44func Encrypt(c Crypter, payload gather.Bytes, prefix, suffix blob.ID, output *gather.WriteBuffer) (blob.ID, error) {
45 var hashOutput [hashing.MaxHashSize]byte
46
47 hash := c.HashFunc()(hashOutput[:0], payload)
48 blobID := prefix + blob.ID(hex.EncodeToString(hash))
49
50 if suffix != "" {
51 blobID += "-" + suffix
52 }
53
54 iv, err := getIndexBlobIV(blobID)
55 if err != nil {
56 return "", err
57 }
58
59 output.Reset()
60
61 if err := c.Encryptor().Encrypt(payload, iv, output); err != nil {
62 return "", errors.Wrapf(err, "error encrypting BLOB %v", blobID)
63 }
64
65 return blobID, nil
66}
67
68// Decrypt decrypts the provided data using provided blobID to derive initialization vector.
69func Decrypt(c Crypter, payload gather.Bytes, blobID blob.ID, output *gather.WriteBuffer) error {

Callers 7

EncryptAndWriteBlobMethod · 0.92
CompactEpochMethod · 0.92
WriteIndexBlobsMethod · 0.92
TestBlobCryptoFunction · 0.85
TestBlobCrypto_InvalidFunction · 0.85

Calls 6

IDTypeAlias · 0.92
getIndexBlobIVFunction · 0.85
HashFuncMethod · 0.65
ResetMethod · 0.65
EncryptMethod · 0.65
EncryptorMethod · 0.65

Tested by 2

TestBlobCryptoFunction · 0.68
TestBlobCrypto_InvalidFunction · 0.68