SecureCommunicationsVapor Documentation Beta

Structure Data

@frozen struct Data

A byte buffer in memory

Methods

seal​AES(sender​Private​Key:​recipient​Public​Key:​salt:​)

public func sealAES(senderPrivateKey: P256.KeyAgreement.PrivateKey, recipientPublicKey: P256.KeyAgreement.PublicKey, salt: Data) -> Data?

Encrypts current data using AES.GCM cipher.

Parameters

sender​Private​Key P256.​Key​Agreement.​Private​Key

Sender private key.

recipient​Public​Key P256.​Key​Agreement.​Public​Key

Recipient public key.

salt Data

The salt to use for key derivation.

Returns

Combined AES Selead box (nonce || ciphertext || tag). If there's a problem encrypting, nil is retuned.

open​AES(recipient​Private​Key:​sender​Public​Key:​salt:​)

public func openAES(recipientPrivateKey: P256.KeyAgreement.PrivateKey, senderPublicKey: P256.KeyAgreement.PublicKey, salt: Data) -> Data?

Decrypts current combined AES Selead box data (nonce || ciphertext || tag) using AES.GCM cipher.

Parameters

recipient​Private​Key P256.​Key​Agreement.​Private​Key

Recipient private key.

sender​Public​Key P256.​Key​Agreement.​Public​Key

Sender public key.

salt Data

The salt to use for key derivation.

Returns

Decrypts the message and verifies its authenticity using AES.GCM. If there's a problem decrypting, nil is retuned.

seal​Cha​Cha​Poly(sender​Private​Key:​recipient​Public​Key:​salt:​)

public func sealChaChaPoly(senderPrivateKey: P256.KeyAgreement.PrivateKey, recipientPublicKey: P256.KeyAgreement.PublicKey, salt: Data) -> Data?

Encrypts current data using ChaChaPoly cipher.

Parameters

sender​Private​Key P256.​Key​Agreement.​Private​Key

Sender private key.

recipient​Public​Key P256.​Key​Agreement.​Public​Key

Recipient public key.

salt Data

The salt to use for key derivation.

Returns

Combined ChaChaPoly Selead box (nonce || ciphertext || tag). If there's a problem encrypting, nil is retuned.

open​Cha​Cha​Poly(recipient​Private​Key:​sender​Public​Key:​salt:​)

public func openChaChaPoly(recipientPrivateKey: P256.KeyAgreement.PrivateKey, senderPublicKey: P256.KeyAgreement.PublicKey, salt: Data) -> Data?

Decrypts current combined ChaChaPoly Selead box data (nonce || ciphertext || tag) using ChaChaPoly cipher.

Parameters

recipient​Private​Key P256.​Key​Agreement.​Private​Key

Recipient private key.

sender​Public​Key P256.​Key​Agreement.​Public​Key

Sender public key.

salt Data

The salt to use for key derivation.

Returns

Decrypts the message and verifies its authenticity using ChaChaPoly. If there's a problem decrypting, nil is retuned.

authentication​Code​HMAC(sender​Private​Key:​recipient​Public​Key:​salt:​)

public func authenticationCodeHMAC(senderPrivateKey: P256.KeyAgreement.PrivateKey, recipientPublicKey: P256.KeyAgreement.PublicKey, salt: Data) -> Data?

Computes a message authentication code for the given data using HMAC from current data.

Parameters

sender​Private​Key P256.​Key​Agreement.​Private​Key

Sender private key.

recipient​Public​Key P256.​Key​Agreement.​Public​Key

Recipient public key.

salt Data

The salt to use for key derivation.

Returns

Message authentication code. If there's a problem computing, nil is retuned.

is​Valid​Authentication​Code​HMAC(recipient​Private​Key:​authentication​Code:​sender​Public​Key:​salt:​)

public func isValidAuthenticationCodeHMAC(recipientPrivateKey: P256.KeyAgreement.PrivateKey, authenticationCode: Data, senderPublicKey: P256.KeyAgreement.PublicKey, salt: Data) -> Bool

Returns a Boolean indicating whether the given code is valid for current data using HMAC.

Parameters

recipient​Private​Key P256.​Key​Agreement.​Private​Key

Recipient private key.

authentication​Code Data

authentication code to validate.

sender​Public​Key P256.​Key​Agreement.​Public​Key

Sender public key.

salt Data

The salt to use for key derivation.

Returns

Boolean indicating whether the given code is valid for current data. If there's a problem validating, false is retuned.