Пример #1
0
Файл: pm.go Проект: logan/heim
func (pm *PM) transmitToAccount(kms security.KMS, pmKey *security.ManagedKey, receiver Account) (*PM, error) {
	userKey := receiver.SystemKey()
	if err := kms.DecryptKey(&userKey); err != nil {
		return nil, err
	}

	encryptedReceiverKey := pmKey.Clone()
	encryptedReceiverKey.IV = pm.IV
	if err := encryptedReceiverKey.Encrypt(&userKey); err != nil {
		return nil, err
	}

	pm.EncryptedReceiverKey = &encryptedReceiverKey
	return pm, nil
}
Пример #2
0
func (a *Agent) SetClientKey(accessKey, clientKey *security.ManagedKey) error {
	if accessKey.Encrypted() || clientKey.Encrypted() {
		return security.ErrKeyMustBeDecrypted
	}

	if !a.verify(accessKey) {
		return ErrAccessDenied
	}

	encryptedClientKey := clientKey.Clone()
	encryptedClientKey.IV = a.IV
	if err := encryptedClientKey.Encrypt(accessKey); err != nil {
		return err
	}

	a.EncryptedClientKey = &encryptedClientKey
	return nil
}