Sodium
struct Sodium
A wrapper for libsodium
that on one hand offers convenient access to the
libsodium
bindings and on the other hand assures that libsodium
was
initialized before actually invoking methods.
-
Access to the wrapper for generic hashing.
Declaration
Swift
let generichash: Sodium.SodiumGenericHash
-
A wrapper for generic hashing.
See moreDeclaration
Swift
struct SodiumGenericHash
-
Access to the key derivation wrapper.
Declaration
Swift
let kdf: Sodium.SodiumKeyDerivation
-
A wrapper for key derivation.
See moreDeclaration
Swift
struct SodiumKeyDerivation
-
Access to the wrapper for key exchange.
Declaration
Swift
let kx: Sodium.SodiumKeyExchange
-
A wrapper for key exchange.
See moreDeclaration
Swift
struct SodiumKeyExchange
-
Access to the secure memory wrapper.
Declaration
Swift
let memory: Sodium.SodiumMemory
-
A wrapper for handling secure memory allocations.
See moreDeclaration
Swift
struct SodiumMemory
-
Access to the password hashing wrapper
Declaration
Swift
let pwhash: Sodium.SodiumPasswordHash
-
A wrapper for password hashing.
See moreDeclaration
Swift
struct SodiumPasswordHash
-
Access to the wrapper for secure random byte generation.
Declaration
Swift
let random: Sodium.SodiumRandom
-
A wrapper for generating random bytes securely.
See moreDeclaration
Swift
struct SodiumRandom
-
Access to the secret box wrapper.
Declaration
Swift
let secretbox: Sodium.SodiumSecretBox
-
A wrapper for symmetric encryption.
See moreDeclaration
Swift
struct SodiumSecretBox
-
Add padding to protect message lengths.
Warning
Padding has to be applied to plaintext before encryption.
Precondition
0 <
blockSize
Postcondition
result.count
%blockSize
= 0Parameters
unpadded
The unpadded plaintext bytes.
blockSize
The block size in bytes.
Return Value
The padded plaintext bytes.
-
Add padding to protect message lengths.
Warning
Padding has to be applied to plaintext before encryption.
Precondition
0 <
blockSize
Postcondition
result.count
%blockSize
= 0Parameters
unpadded
The unpadded plaintext bytes.
blockSize
The block size in bytes.
Return Value
The padded plaintext bytes.
-
Converts hex-characters to a byte array.
Declaration
Swift
func hex2bin(_ hex: String, ignore: String? = nil) -> Bytes?
Parameters
hex
The string.
ignore
A string containing characters that should be ignored, e.g., this is useful to ignore the colon if
hex
is00:11
.Return Value
The byte array.
-
Converts a byte array to a hex-encoded string.
Declaration
Swift
func bin2hex(_ bin: Bytes) -> String
Parameters
bin
The byte array.
Return Value
The hex-encoded string.
-
Converts hex-characters to a byte array.
Declaration
Swift
func b64decode(_ b64: String, ignore: String? = nil) -> Bytes?
Parameters
b64
The string.
ignore
A string containing characters that should be ignored.
Return Value
The byte array.
-
Converts a byte array to a Base64-encoded string.
Declaration
Swift
func b64encode(bytes: Bytes) -> String
Parameters
bin
The byte array.
Return Value
The Base64-encoded string.