storj.io/uplink@v1.13.0/encryption.go (about)

     1  // Copyright (C) 2020 Storj Labs, Inc.
     2  // See LICENSE for copying information.
     3  
     4  package uplink
     5  
     6  import (
     7  	"storj.io/common/encryption"
     8  	"storj.io/common/storj"
     9  )
    10  
    11  // EncryptionKey represents a key for encrypting and decrypting data.
    12  type EncryptionKey struct {
    13  	key *storj.Key
    14  }
    15  
    16  // DeriveEncryptionKey derives a salted encryption key for passphrase using the
    17  // salt.
    18  //
    19  // This function is useful for deriving a salted encryption key for users when
    20  // implementing multitenancy in a single app bucket. See the relevant section in
    21  // the package documentation.
    22  func DeriveEncryptionKey(passphrase string, salt []byte) (*EncryptionKey, error) {
    23  	key, err := encryption.DeriveRootKey([]byte(passphrase), salt, "", 1)
    24  	if err != nil {
    25  		return nil, packageError.Wrap(err)
    26  	}
    27  	return &EncryptionKey{key: key}, nil
    28  }