// NewAESEncryptedStorage creates a new encrypted storage backed by the given file/key
438490
func NewAESEncryptedStorage(filename string, key []byte) *AESEncryptedStorage {
	return &AESEncryptedStorage{
		filename: filename,
		key:      key,
	}
}
83707
func AESEncryptWithECB(str, key []byte) ([]byte, error) {
	cb, err := aes.NewCipher(key)
	if err != nil {
		return nil, errors.Trace(err)
	}
	mode := newECBEncrypter(cb)
	return aesEncrypt(str, mode)
}
1184320
func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) {
	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, err
	}

	gcm, err := cipher.NewGCM(block)
	if err != nil {
		return nil, err
	}

	nonce := make([]byte, gcm.NonceSize())
	if _, err := rand.Read(nonce); err != nil {
		return nil, err
	}

	ciphertext := gcm.Seal(nil, nonce, plaintext, nil)
	return append(nonce, ciphertext...), nil
}
30063
func (s *DBInstanceAutomatedBackup) SetEncrypted(v bool) *DBInstanceAutomatedBackup {
	s.Encrypted = &v
	return s
}
798698
func (e RSAOAEPKeyEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
	var hash hash.Hash
	switch e.alg {
	case jwa.RSA_OAEP:
		hash = sha1.New()
	case jwa.RSA_OAEP_256:
		hash = sha256.New()
	default:
		return nil, errors.New("failed to generate key encrypter for RSA-OAEP: RSA_OAEP/RSA_OAEP_256 required")
	}
	encrypted, err := rsa.EncryptOAEP(hash, rand.Reader, e.pubkey, cek, []byte{})
	if err != nil {
		return nil, errors.Wrap(err, `failed to OAEP encrypt`)
	}
	return ByteKey(encrypted), nil
}
1315698
func NewFilesystemStore(path string, keyPairs ...[]byte) sessions.Store {
	return &filesystemStore{sessions.NewFilesystemStore(path, keyPairs...)}
}
18038
func NewEc2Storage(instance, instanceType string, ec2 *ec2.EC2) storageops.Ops {
	return &ec2Ops{
		instance:     instance,
		instanceType: instanceType,
		ec2:          ec2,
	}
}
100116
func (s *Volume) SetEncrypted(v bool) *Volume {
	s.Encrypted = &v
	return s
}
256305
func (engine *CryptoEngine) NewEncryptedMessage(msg message) (EncryptedMessage, error) {

	m := EncryptedMessage{}

	// derive nonce
	nonce, err := deriveNonce(engine.nonceKey, engine.salt, engine.context, engine.fetchAndIncrement())
	if err != nil {
		return m, err
	}

	m.nonce = nonce

	encryptedData := secretbox.Seal(nil, msg.toBytes(), &m.nonce, &engine.secretKey)

	// assign the encrypted data to the message
	m.data = encryptedData

	// calculate the overall size of the message
	m.length = uint64(len(m.data) + len(m.nonce) + 8)

	return m, nil

}
585981
func NewCrypter(key []byte) (e *Crypter, err error) {
	e = new(Crypter)

	if len(key) != sha512.Size256 {
		return nil, errors.Errorf("whatwhat: wrong key length. Got:%d", len(key))
	}

	e.key = key

	e.block, err = aes.NewCipher(e.key)
	if err != nil {
		return nil, errors.Wrap(err, "whatwhat: couldn't create AES cipher")
	}

	return e, nil
}
47371
func UndecoratedStorage(
	config *storagebackend.Config,
	resourcePrefix string,
	keyFunc func(obj runtime.Object) (string, error),
	newFunc func() runtime.Object,
	newListFunc func() runtime.Object,
	getAttrsFunc storage.AttrFunc,
	trigger storage.TriggerPublisherFunc) (storage.Interface, factory.DestroyFunc) {
	return NewRawStorage(config)
}
1249477
func Aes256ECBDecrypt(key [32]byte, ciphertext []byte) (plaintext []byte, err error) {
	return aesECBDec(key[:], ciphertext)
}
122074
func (s *FileSystemDescription) SetEncrypted(v bool) *FileSystemDescription {
	s.Encrypted = &v
	return s
}
926075
func NewIETFCipher(key []byte) (cipher.AEAD, error) {
	return newCipher(key, chacha.INonceSize)
}
1074396
func NewPlaintextKeyStore(keydir string) *KeyStore {
	keydir, _ = filepath.Abs(keydir)
	ks := &KeyStore{storage: &keyStorePlain{keydir}}
	ks.init(keydir)
	return ks
}
138865
func (s *AESEncryptedStorage) Put(key, value string) {
	if len(key) == 0 {
		return
	}
	data, err := s.readEncryptedStorage()
	if err != nil {
		log.Warn("Failed to read encrypted storage", "err", err, "file", s.filename)
		return
	}
	ciphertext, iv, err := encrypt(s.key, []byte(value), []byte(key))
	if err != nil {
		log.Warn("Failed to encrypt entry", "err", err)
		return
	}
	encrypted := storedCredential{Iv: iv, CipherText: ciphertext}
	data[key] = encrypted
	if err = s.writeEncryptedStorage(data); err != nil {
		log.Warn("Failed to write entry", "err", err)
	}
}
923269
func NewBackupContext(targetDir string, env map[string]string, cryptKey string) (backupContext BackupContext) {
	backupContext = BackupContext{
		TargetDir: targetDir,
	}
	if useS3(env) {
		backupContext.StorageProvider = NewS3Provider(env[S3Domain], env[AccessKeyIDVarname], env[SecretAccessKeyVarname], env[BucketNameVarname])
		backupContext.IsS3 = true
	} else {
		backupContext.StorageProvider = NewDiskProvider()
	}

	if isValidCryptKey(cryptKey) {
		var err error

		if backupContext.StorageProvider, err = NewEncryptedStorageProvider(backupContext.StorageProvider, cryptKey); err != nil {
			lo.G.Error("something went wrong when applying encryption to storage provider: ", err)
			panic(err)
		}
	}
	return
}