SecureCommunications Documentation Beta

Structure String

@frozen struct String

A Unicode string value that is a collection of characters

Methods

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

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

Encrypts current string using AES.GCM cipher.

Parameters

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

Recipient public key.

salt String

The salt to use for key derivation.

Returns

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

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

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

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

Parameters

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

Sender public key.

salt String

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(recipient​Public​Key:​salt:​)

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

Encrypts current string using ChaChaPoly cipher.

Parameters

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

Recipient public key.

salt String

The salt to use for key derivation.

Returns

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

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

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

Decrypts current ChaChaPoly Selead box coded combined as nonce || ciphertext || tag and coded on Base64 using ChaChaPoly cipher.

Parameters

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

Sender public key.

salt String

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(recipient​Public​Key:​salt:​)

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

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

Parameters

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

Recipient public key.

salt String

The salt to use for key derivation.

Returns

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

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

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

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

Parameters

authentication​Code String

authentication code to validate coded on Base64.

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

Sender public key.

salt String

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.